diff --git a/DSView/main.cpp b/DSView/main.cpp index e1714572..862befdf 100755 --- a/DSView/main.cpp +++ b/DSView/main.cpp @@ -19,10 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -#include -#include - + #include #include @@ -35,11 +32,11 @@ #include #include "dsapplication.h" -#include "mystyle.h" -#include "pv/devicemanager.h" +#include "mystyle.h" #include "pv/mainframe.h" #include "pv/config/appconfig.h" #include "config.h" +#include "pv/appcontrol.h" char DS_RES_PATH[256]; @@ -58,10 +55,9 @@ void usage() int main(int argc, char *argv[]) { - int ret = 0; - struct sr_context *sr_ctx = NULL; + int ret = 0; const char *open_file = NULL; - + #if QT_VERSION >= QT_VERSION_CHECK(5,6,0) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); @@ -107,6 +103,8 @@ int main(int argc, char *argv[]) QApplication::setOrganizationName("DreamSourceLab"); QApplication::setOrganizationDomain("www.DreamSourceLab.com"); + AppControl *control = AppControl::Instance(); + // Parse arguments while (1) { static const struct option long_options[] = { @@ -125,12 +123,7 @@ int main(int argc, char *argv[]) case 'l': { const int loglevel = atoi(optarg); - sr_log_loglevel_set(loglevel); - - - srd_log_loglevel_set(loglevel); - - + control->SetLogLevel(loglevel); break; } @@ -166,53 +159,41 @@ int main(int argc, char *argv[]) return 1; } - // Initialise libsigrok - if (sr_init(&sr_ctx) != SR_OK) { - qDebug() << "DSView run ERROR: libsigrok init failed."; + //load app config + AppConfig::Instance().LoadAll(); + + //init core + if (!control->Init()){ + fprintf(stderr, "init error!"); + qDebug() << control->GetLastError(); return 1; } - do { + try + { + control->Start(); + + // Initialise the main frame + pv::MainFrame w; + w.show(); + w.readSettings(); + + //to show the dailog for open help document + w.show_doc(); - // Initialise libsigrokdecode - if (srd_init(NULL) != SRD_OK) { - qDebug() << "ERROR: libsigrokdecode init failed."; - break; - } + //Run the application + ret = a.exec(); + } + catch (const std::exception &e) + { + fprintf(stderr, "main() catch a except!"); + const char *exstr = e.what(); + qDebug() << exstr; + } - // Load the protocol decoders - srd_decoder_load_all(); - - //load app config - AppConfig::Instance().LoadAll(); - - try { - // Create the device manager, initialise the drivers - pv::DeviceManager device_manager(sr_ctx); - - // Initialise the main frame - pv::MainFrame w(device_manager, open_file); - w.show(); - w.readSettings(); - w.show_doc(); // to show the dailog for open help document - - // Run the application - ret = a.exec(); - - } catch(const std::exception &e) { - qDebug() << e.what(); - } - - - // Destroy libsigrokdecode - srd_exit(); - - - } while (0); - - // Destroy libsigrok - if (sr_ctx) - sr_exit(sr_ctx); + //uninit + control->UnInit(); + control->Destroy(); return ret; } diff --git a/DSView/pv/appcontrol.cpp b/DSView/pv/appcontrol.cpp new file mode 100644 index 00000000..9cf40035 --- /dev/null +++ b/DSView/pv/appcontrol.cpp @@ -0,0 +1,123 @@ + +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "appcontrol.h" + +#include +#include + +#include "devicemanager.h" +#include "sigsession.h" +#include "dsvdef.h" + +AppControl::AppControl() +{ + sr_ctx = NULL; + + _device_manager = new pv::DeviceManager(); + _session = new pv::SigSession(_device_manager); + _session->_appCntrol = this; +} + +AppControl::AppControl(AppControl &o) +{ + (void)o; +} + +AppControl::~AppControl() +{ + DESTROY_OBJECT(_device_manager); + DESTROY_OBJECT(_session); +} + +AppControl* AppControl::Instance() +{ + static AppControl *ins = NULL; + if (ins == NULL){ + ins = new AppControl(); + } + return ins; +} + +void AppControl::Destroy(){ + delete this; +} + +bool AppControl::Init() +{ + // Initialise libsigrok + if (sr_init(&sr_ctx) != SR_OK) + { + m_error = "DSView run ERROR: libsigrok init failed."; + return false; + } + + // Initialise libsigrokdecode + if (srd_init(NULL) != SRD_OK) + { + m_error = "ERROR: libsigrokdecode init failed."; + return false; + } + + // Load the protocol decoders + if (srd_decoder_load_all() != SRD_OK) + { + m_error = "ERROR: load the protocol decoders failed."; + return false; + } + + return true; +} + +bool AppControl::Start() +{ + _session->Open(); + _device_manager->initAll(sr_ctx); + return true; +} + +void AppControl::UnInit() +{ + _session->Close(); + _device_manager->UnInitAll(); + + // Destroy libsigrokdecode + srd_exit(); + + if (sr_ctx) + { + sr_exit(sr_ctx); + sr_ctx = NULL; + } +} + +const char *AppControl::GetLastError() +{ + return m_error.c_str(); +} + + void AppControl::SetLogLevel(int level) + { + sr_log_loglevel_set(level); + srd_log_loglevel_set(level); + } diff --git a/DSView/pv/appcontrol.h b/DSView/pv/appcontrol.h new file mode 100644 index 00000000..ff2742b5 --- /dev/null +++ b/DSView/pv/appcontrol.h @@ -0,0 +1,68 @@ + +/* + * This file is part of the DSView project. + * DSView is based on PulseView. + * + * Copyright (C) 2012 Joel Holdsworth + * Copyright (C) 2013 DreamSourceLab + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#pragma once + +#include + +struct sr_context; + +namespace pv{ + class DeviceManager; + class SigSession; +} + +class AppControl +{ +private: + explicit AppControl(); + ~AppControl(); + AppControl(AppControl &o); + +public: + static AppControl* Instance(); + + void Destroy(); + + bool Init(); + + bool Start(); + + void UnInit(); + + const char* GetLastError(); + + void SetLogLevel(int level); + + inline pv::SigSession* GetSession() + { return _session;} + + inline pv::DeviceManager& GetDeviceManager() + { return *_device_manager;} + +private: + std::string m_error; + struct sr_context *sr_ctx; + pv::DeviceManager *_device_manager; + pv::SigSession *_session; +}; diff --git a/DSView/pv/config/appconfig.cpp b/DSView/pv/config/appconfig.cpp index ae3fcd24..269b261f 100644 --- a/DSView/pv/config/appconfig.cpp +++ b/DSView/pv/config/appconfig.cpp @@ -173,6 +173,11 @@ AppConfig::AppConfig() { } +AppConfig::AppConfig(AppConfig &o) +{ + (void)o; +} + AppConfig::~AppConfig() { } diff --git a/DSView/pv/config/appconfig.h b/DSView/pv/config/appconfig.h index 7bae2732..224baf8d 100644 --- a/DSView/pv/config/appconfig.h +++ b/DSView/pv/config/appconfig.h @@ -81,6 +81,7 @@ class AppConfig private: AppConfig(); ~AppConfig(); + AppConfig(AppConfig &o); public: static AppConfig &Instance(); diff --git a/DSView/pv/data/decoderstack.cpp b/DSView/pv/data/decoderstack.cpp index 7f946dd1..c9bbd504 100755 --- a/DSView/pv/data/decoderstack.cpp +++ b/DSView/pv/data/decoderstack.cpp @@ -52,7 +52,7 @@ const unsigned int DecoderStack::DecodeNotifyPeriod = 1024; boost::mutex DecoderStack::_global_decode_mutex; -DecoderStack::DecoderStack(pv::SigSession &session, +DecoderStack::DecoderStack(pv::SigSession *session, const srd_decoder *const dec, DecoderStatus *decoder_status) : _session(session), _sample_count(0), @@ -63,11 +63,11 @@ DecoderStack::DecoderStack(pv::SigSession &session, _no_memory(false), _mark_index(-1) { - connect(&_session, SIGNAL(frame_began()), + connect(_session, SIGNAL(frame_began()), this, SLOT(on_new_frame())); - connect(&_session, SIGNAL(data_received()), + connect(_session, SIGNAL(data_received()), this, SLOT(on_data_received())); - connect(&_session, SIGNAL(frame_ended()), + connect(_session, SIGNAL(frame_ended()), this, SLOT(on_frame_ended())); _stack.push_back(boost::shared_ptr( @@ -419,7 +419,7 @@ void DecoderStack::begin_decode() // LogicSignals have the same data/snapshot BOOST_FOREACH (const boost::shared_ptr &dec, _stack) { if (dec && !dec->channels().empty()) { - BOOST_FOREACH(boost::shared_ptr sig, _session.get_signals()) { + BOOST_FOREACH(boost::shared_ptr sig, _session->get_signals()) { if((sig->get_index() == (*dec->channels().begin()).second) && (logic_signal = dynamic_pointer_cast(sig)) && (data = logic_signal->logic_data())) diff --git a/DSView/pv/data/decoderstack.h b/DSView/pv/data/decoderstack.h index 311a819f..bc05fa6b 100755 --- a/DSView/pv/data/decoderstack.h +++ b/DSView/pv/data/decoderstack.h @@ -79,7 +79,7 @@ public: }; public: - DecoderStack(pv::SigSession &_session, + DecoderStack(pv::SigSession *_session, const srd_decoder *const decoder, DecoderStatus *decoder_status); public: @@ -168,7 +168,7 @@ signals: void decode_done(); private: - pv::SigSession &_session; + pv::SigSession *_session; /** * This mutex prevents more than one decode operation occuring diff --git a/DSView/pv/data/mathstack.cpp b/DSView/pv/data/mathstack.cpp index 759b53b3..072d0dfe 100755 --- a/DSView/pv/data/mathstack.cpp +++ b/DSView/pv/data/mathstack.cpp @@ -75,7 +75,7 @@ const QString MathStack::vDialDivUnit[MathStack::vDialUnitCount] = { "V/V", }; -MathStack::MathStack(pv::SigSession &session, +MathStack::MathStack(pv::SigSession *session, boost::shared_ptr dsoSig1, boost::shared_ptr dsoSig2, MathType type) : diff --git a/DSView/pv/data/mathstack.h b/DSView/pv/data/mathstack.h index ffb80db4..7f6f9844 100755 --- a/DSView/pv/data/mathstack.h +++ b/DSView/pv/data/mathstack.h @@ -102,7 +102,7 @@ private: static const QString vDialDivUnit[vDialUnitCount]; public: - MathStack(pv::SigSession &_session, + MathStack(pv::SigSession *_session, boost::shared_ptr dsoSig1, boost::shared_ptr dsoSig2, MathType type); virtual ~MathStack(); @@ -132,7 +132,7 @@ public: signals: private: - pv::SigSession &_session; + pv::SigSession *_session; boost::shared_ptr _dsoSig1; boost::shared_ptr _dsoSig2; diff --git a/DSView/pv/data/spectrumstack.cpp b/DSView/pv/data/spectrumstack.cpp index d040eb9b..b54bddff 100755 --- a/DSView/pv/data/spectrumstack.cpp +++ b/DSView/pv/data/spectrumstack.cpp @@ -52,7 +52,7 @@ const uint64_t SpectrumStack::length_support[5] = { 16384, }; -SpectrumStack::SpectrumStack(pv::SigSession &session, int index) : +SpectrumStack::SpectrumStack(pv::SigSession *session, int index) : _session(session), _index(index), _dc_ignore(true), @@ -173,7 +173,7 @@ void SpectrumStack::calc_fft() // Get the dso data boost::shared_ptr data; boost::shared_ptr dsoSig; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { if ((dsoSig = dynamic_pointer_cast(s))) { if (dsoSig->get_index() == _index && dsoSig->enabled()) { data = dsoSig->dso_data(); diff --git a/DSView/pv/data/spectrumstack.h b/DSView/pv/data/spectrumstack.h index caa4d268..82440595 100755 --- a/DSView/pv/data/spectrumstack.h +++ b/DSView/pv/data/spectrumstack.h @@ -63,7 +63,7 @@ public: }; public: - SpectrumStack(pv::SigSession &_session, int index); + SpectrumStack(pv::SigSession *_session, int index); virtual ~SpectrumStack(); void clear(); void init(); @@ -95,7 +95,7 @@ public: signals: private: - pv::SigSession &_session; + pv::SigSession *_session; int _index; uint64_t _sample_num; diff --git a/DSView/pv/device/device.cpp b/DSView/pv/device/device.cpp index 4eb77b33..ab60d5a8 100755 --- a/DSView/pv/device/device.cpp +++ b/DSView/pv/device/device.cpp @@ -33,6 +33,13 @@ Device::Device(sr_dev_inst *sdi) : _sdi(sdi) { assert(_sdi); + void *p = this; + (void)p; +} + +Device::~Device() +{ + } sr_dev_inst* Device::dev_inst() const diff --git a/DSView/pv/device/device.h b/DSView/pv/device/device.h index f1ec24f1..77ed9abe 100755 --- a/DSView/pv/device/device.h +++ b/DSView/pv/device/device.h @@ -28,10 +28,12 @@ namespace pv { namespace device { class Device : public DevInst -{ +{ public: Device(sr_dev_inst *dev_inst); + ~Device(); + sr_dev_inst* dev_inst() const; void use(SigSession *owner); diff --git a/DSView/pv/device/devinst.cpp b/DSView/pv/device/devinst.cpp index 6aeeeb87..d06858cb 100755 --- a/DSView/pv/device/devinst.cpp +++ b/DSView/pv/device/devinst.cpp @@ -61,7 +61,6 @@ void DevInst::release() { if (_owner) { _owner->release_device(this); - _owner = NULL; } } @@ -210,5 +209,10 @@ bool DevInst::is_usable() const return _usable; } +void DevInst::destroy(){ + release(); + delete this; +} + } // device } // pv diff --git a/DSView/pv/device/devinst.h b/DSView/pv/device/devinst.h index b7c7f8c3..8039fddd 100755 --- a/DSView/pv/device/devinst.h +++ b/DSView/pv/device/devinst.h @@ -22,8 +22,6 @@ #ifndef DSVIEW_PV_DEVICE_DEVINST_H #define DSVIEW_PV_DEVICE_DEVINST_H -#include - #include #include @@ -48,19 +46,12 @@ class DevInst : public QObject protected: DevInst(); - ~DevInst(); -public: - virtual sr_dev_inst* dev_inst() const = 0; - - virtual void use(SigSession *owner); - - virtual void release(); + virtual ~DevInst(); +public: SigSession* owner() const; - - virtual QString format_device_title() const = 0; - + GVariant* get_config(const sr_channel *ch, const sr_channel_group *group, int key); bool set_config(sr_channel *ch, sr_channel_group *group, int key, GVariant *data); @@ -115,11 +106,12 @@ public: * @return device name */ QString name(); - - virtual bool is_trigger_enabled() const; + bool is_usable() const; + void destroy(); + public: virtual void start(); @@ -127,6 +119,16 @@ public: virtual void* get_id() const; + virtual sr_dev_inst* dev_inst() const = 0; + + virtual void use(SigSession *owner); + + virtual void release(); + + virtual bool is_trigger_enabled() const; + + virtual QString format_device_title() const = 0; + signals: void device_updated(); void config_changed(); diff --git a/DSView/pv/device/file.cpp b/DSView/pv/device/file.cpp index 7efee676..eb494b04 100755 --- a/DSView/pv/device/file.cpp +++ b/DSView/pv/device/file.cpp @@ -39,6 +39,10 @@ File::File(QString path) : { } +File::~File(){ + +} + QString File::format_device_title() const { QFileInfo fi(_path); diff --git a/DSView/pv/device/file.h b/DSView/pv/device/file.h index d4299e7b..a4984170 100755 --- a/DSView/pv/device/file.h +++ b/DSView/pv/device/file.h @@ -35,10 +35,13 @@ namespace device { class File : public DevInst { + protected: File(QString path); public: + ~File(); + static File* create(QString name); QJsonArray get_decoders(); diff --git a/DSView/pv/devicemanager.cpp b/DSView/pv/devicemanager.cpp index 08bf0946..488d3e61 100755 --- a/DSView/pv/devicemanager.cpp +++ b/DSView/pv/devicemanager.cpp @@ -34,9 +34,6 @@ #include #include -#include - -using boost::shared_ptr; using std::list; using std::map; using std::ostringstream; @@ -45,57 +42,64 @@ using std::string; namespace pv { -DeviceManager::DeviceManager(struct sr_context *sr_ctx) : - _sr_ctx(sr_ctx) +DeviceManager::DeviceManager() { - init_drivers(); - scan_all_drivers(); + _sr_ctx = NULL; +} + +DeviceManager::DeviceManager(DeviceManager &o) +{ + (void)o; } DeviceManager::~DeviceManager() { - release_devices(); + } -const std::list > &DeviceManager::devices() const +void DeviceManager::initAll(struct sr_context *sr_ctx) +{ + _sr_ctx = sr_ctx; + init_drivers(); + scan_all_drivers(); +} + + void DeviceManager::UnInitAll() + { + release_devices(); + } + +void DeviceManager::add_device(DevInst *device) { - return _devices; + assert(device); + + auto it = std::find(_devices.begin(), _devices.end(), device); + if (it ==_devices.end()){ + _devices.push_front(device); + } } -void DeviceManager::add_device(boost::shared_ptr device) +void DeviceManager::del_device(DevInst *device) { assert(device); - if (std::find(_devices.begin(), _devices.end(), device) == - _devices.end()) - _devices.push_front(device); -} - -void DeviceManager::del_device(boost::shared_ptr device) -{ - assert(device); - BOOST_FOREACH(shared_ptr dev, _devices) { - assert(dev); - if(dev == device) { - dev->release(); - break; - } + auto it = std::find(_devices.begin(), _devices.end(), device); + if (it !=_devices.end()){ + _devices.erase(it); //remove from list + device->destroy(); } - if (std::find(_devices.begin(), _devices.end(), device) != - _devices.end()) - _devices.remove(device); } -std::list > DeviceManager::driver_scan( +std::list& DeviceManager::driver_scan( struct sr_dev_driver *const driver, GSList *const drvopts) { - list< shared_ptr > driver_devices; + list 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 >::iterator i = _devices.begin(); + auto i = _devices.begin(); while (i != _devices.end()) { if ((*i)->dev_inst() && (*i)->dev_inst()->driver == driver) { @@ -119,16 +123,16 @@ std::list > 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_front(shared_ptr( - new device::Device((sr_dev_inst*)l->data))); - g_slist_free(devices); - //driver_devices.sort(compare_devices); - // Add the scanned devices to the main list - _devices.insert(_devices.end(), driver_devices.begin(), - driver_devices.end()); - //_devices.sort(compare_devices); + for (GSList *l = devices; l; l = l->next){ + Device *dev = new device::Device((sr_dev_inst*)l->data); //create new device + driver_devices.push_front(dev); + } + + g_slist_free(devices); + + // append the scanned devices to the main list + _devices.insert(_devices.end(), driver_devices.begin(), driver_devices.end()); return driver_devices; } @@ -149,8 +153,7 @@ void DeviceManager::init_drivers() void DeviceManager::release_devices() { // Release all the used devices - BOOST_FOREACH(shared_ptr dev, _devices) { - assert(dev); + for (DevInst *dev : _devices) { dev->release(); } @@ -170,8 +173,7 @@ void DeviceManager::scan_all_drivers() void DeviceManager::release_driver(struct sr_dev_driver *const driver) { - BOOST_FOREACH(shared_ptr dev, _devices) { - assert(dev); + for (DevInst *dev : _devices) { if(dev->dev_inst()->driver == driver) dev->release(); } @@ -180,8 +182,7 @@ void DeviceManager::release_driver(struct sr_dev_driver *const driver) sr_dev_clear(driver); } -bool DeviceManager::compare_devices(boost::shared_ptr a, - boost::shared_ptr b) +bool DeviceManager::compare_devices(DevInst *a, DevInst *b) { assert(a); assert(b); diff --git a/DSView/pv/devicemanager.h b/DSView/pv/devicemanager.h index 426b9aa8..b275b69b 100755 --- a/DSView/pv/devicemanager.h +++ b/DSView/pv/devicemanager.h @@ -30,8 +30,7 @@ #include #include -#include -#include +#include #include #include @@ -51,21 +50,30 @@ namespace device { class DevInst; } +using namespace pv::device; + class DeviceManager { +private: + DeviceManager(DeviceManager &o); + public: - DeviceManager(struct sr_context *sr_ctx); + DeviceManager(); ~DeviceManager(); - const std::list< boost::shared_ptr >& devices() const; + inline const std::list& devices(){ + return _devices; + } - void add_device(boost::shared_ptr device); - void del_device(boost::shared_ptr device); + void add_device(DevInst *device); + void del_device(DevInst *device); - std::list< boost::shared_ptr > driver_scan( - struct sr_dev_driver *const driver, - GSList *const drvopts = NULL); + std::list& driver_scan(struct sr_dev_driver *const driver, GSList *const drvopts = NULL); + + void initAll(struct sr_context *sr_ctx); + + void UnInitAll(); private: void init_drivers(); @@ -76,12 +84,11 @@ private: void release_driver(struct sr_dev_driver *const driver); - static bool compare_devices(boost::shared_ptr a, - boost::shared_ptr b); + static bool compare_devices(DevInst *a, DevInst *b); private: - struct sr_context *const _sr_ctx; - std::list< boost::shared_ptr > _devices; + struct sr_context* _sr_ctx; + std::list _devices; }; } // namespace pv diff --git a/DSView/pv/dialogs/calibration.cpp b/DSView/pv/dialogs/calibration.cpp index e91d1722..2a5b0a8a 100755 --- a/DSView/pv/dialogs/calibration.cpp +++ b/DSView/pv/dialogs/calibration.cpp @@ -121,7 +121,7 @@ void Calibration::retranslateUi() setTitle(tr("Manual Calibration")); } -void Calibration::set_device(boost::shared_ptr dev_inst) +void Calibration::set_device(DevInst *dev_inst) { assert(dev_inst); _dev_inst = dev_inst; diff --git a/DSView/pv/dialogs/calibration.h b/DSView/pv/dialogs/calibration.h index 8418606e..5764ce14 100755 --- a/DSView/pv/dialogs/calibration.h +++ b/DSView/pv/dialogs/calibration.h @@ -36,6 +36,8 @@ #include "../toolbars/titlebar.h" #include "dsdialog.h" +using namespace pv::device; + namespace pv { namespace dialogs { @@ -52,7 +54,7 @@ public: Calibration(QWidget *parent); ~Calibration(); - void set_device(boost::shared_ptr dev_inst); + void set_device(DevInst *dev_inst); protected: void accept(); void reject(); @@ -69,7 +71,7 @@ private slots: void reload_value(); private: - boost::shared_ptr _dev_inst; + DevInst *_dev_inst; QPushButton *_save_btn; QPushButton *_abort_btn; diff --git a/DSView/pv/dialogs/deviceoptions.cpp b/DSView/pv/dialogs/deviceoptions.cpp index fe8513ed..bfa6fe25 100755 --- a/DSView/pv/dialogs/deviceoptions.cpp +++ b/DSView/pv/dialogs/deviceoptions.cpp @@ -38,7 +38,7 @@ using namespace std; namespace pv { namespace dialogs { -DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptr dev_inst) : +DeviceOptions::DeviceOptions(QWidget *parent, DevInst *dev_inst) : DSDialog(parent), _dev_inst(dev_inst), _button_box(QDialogButtonBox::Ok, Qt::Horizontal, this), @@ -67,7 +67,7 @@ DeviceOptions::DeviceOptions(QWidget *parent, boost::shared_ptrget_config(NULL, NULL, SR_CONF_OPERATION_MODE); if (gvar != NULL) { diff --git a/DSView/pv/dialogs/deviceoptions.h b/DSView/pv/dialogs/deviceoptions.h index ae803c8a..38ee0798 100755 --- a/DSView/pv/dialogs/deviceoptions.h +++ b/DSView/pv/dialogs/deviceoptions.h @@ -47,6 +47,8 @@ #include "../toolbars/titlebar.h" #include "../dialogs/dsdialog.h" +using namespace pv::device; + namespace pv { namespace dialogs { @@ -55,7 +57,7 @@ class DeviceOptions : public DSDialog Q_OBJECT public: - DeviceOptions(QWidget *parent, boost::shared_ptr dev_inst); + DeviceOptions(QWidget *parent, DevInst *dev_inst); ~DeviceOptions(); @@ -85,7 +87,7 @@ private slots: void channel_enable(); private: - boost::shared_ptr _dev_inst; + DevInst *_dev_inst; QVBoxLayout _layout; QGroupBox *_dynamic_box; diff --git a/DSView/pv/dialogs/dsomeasure.cpp b/DSView/pv/dialogs/dsomeasure.cpp index a454d86c..c5f97510 100755 --- a/DSView/pv/dialogs/dsomeasure.cpp +++ b/DSView/pv/dialogs/dsomeasure.cpp @@ -40,7 +40,7 @@ using namespace pv::view; namespace pv { namespace dialogs { -DsoMeasure::DsoMeasure(SigSession &session, View &parent, +DsoMeasure::DsoMeasure(SigSession *session, View &parent, unsigned int position, int last_sig_index) : DSDialog((QWidget *)&parent), _session(session), @@ -57,7 +57,7 @@ DsoMeasure::DsoMeasure(SigSession &session, View &parent, _measure_tab->setTabPosition(QTabWidget::West); _measure_tab->setUsesScrollButtons(false); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s)) && dsoSig->enabled()) { QWidget *measure_widget = new QWidget(this); @@ -79,7 +79,7 @@ DsoMeasure::DsoMeasure(SigSession &session, View &parent, connect(_button_box.button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject())); connect(_button_box.button(QDialogButtonBox::Reset), SIGNAL(clicked()), this, SLOT(reset())); - connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } DsoMeasure::~DsoMeasure(){ @@ -158,7 +158,7 @@ void DsoMeasure::accept() if(sc != NULL) { QVariant id = sc->property("id"); enum DSO_MEASURE_TYPE ms_type = DSO_MEASURE_TYPE(id.toInt()); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { if (_measure_tab->currentWidget()->property("index").toInt() == dsoSig->get_index()) { diff --git a/DSView/pv/dialogs/dsomeasure.h b/DSView/pv/dialogs/dsomeasure.h index 5016fda7..11efed12 100755 --- a/DSView/pv/dialogs/dsomeasure.h +++ b/DSView/pv/dialogs/dsomeasure.h @@ -49,7 +49,7 @@ class DsoMeasure : public DSDialog Q_OBJECT public: - DsoMeasure(SigSession &session, view::View &parent, unsigned int position, int last_sig_index); + DsoMeasure(SigSession *session, view::View &parent, unsigned int position, int last_sig_index); ~DsoMeasure(); @@ -68,7 +68,7 @@ protected: void reject(); private: - SigSession &_session; + SigSession *_session; view::View &_view; unsigned int _position; diff --git a/DSView/pv/dialogs/fftoptions.cpp b/DSView/pv/dialogs/fftoptions.cpp index 9202500d..5af442e7 100755 --- a/DSView/pv/dialogs/fftoptions.cpp +++ b/DSView/pv/dialogs/fftoptions.cpp @@ -38,7 +38,7 @@ using namespace std; namespace pv { namespace dialogs { -FftOptions::FftOptions(QWidget *parent, SigSession &session) : +FftOptions::FftOptions(QWidget *parent, SigSession *session) : DSDialog(parent), _session(session), _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, @@ -67,7 +67,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) : _dbv_combobox = new QComboBox(this); // setup _ch_combobox - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { _ch_combobox->addItem(dsoSig->get_name(), QVariant::fromValue(dsoSig->get_index())); @@ -76,7 +76,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) : // setup _window_combobox _len_combobox _sample_limit = 0; - GVariant* gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLELIMITS); + GVariant* gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MAX_DSO_SAMPLELIMITS); if (gvar != NULL) { _sample_limit = g_variant_get_uint64(gvar) * 0.5; g_variant_unref(gvar); @@ -87,7 +87,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) : std::vector length; std::vector view_modes; std::vector dbv_ranges; - BOOST_FOREACH(const boost::shared_ptr t, _session.get_spectrum_traces()) { + BOOST_FOREACH(const boost::shared_ptr t, _session->get_spectrum_traces()) { boost::shared_ptr spectrumTraces; if ((spectrumTraces = dynamic_pointer_cast(t))) { windows = spectrumTraces->get_spectrum_stack()->get_windows_support(); @@ -137,7 +137,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) : } // load current settings - BOOST_FOREACH(const boost::shared_ptr t, _session.get_spectrum_traces()) { + BOOST_FOREACH(const boost::shared_ptr t, _session->get_spectrum_traces()) { boost::shared_ptr spectrumTraces; if ((spectrumTraces = dynamic_pointer_cast(t))) { if (spectrumTraces->enabled()) { @@ -217,7 +217,7 @@ FftOptions::FftOptions(QWidget *parent, SigSession &session) : connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); connect(_window_combobox, SIGNAL(currentIndexChanged(QString)), this, SLOT(window_changed(QString))); connect(_len_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(len_changed(int))); - connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } FftOptions::~FftOptions(){ @@ -230,7 +230,7 @@ void FftOptions::accept() QDialog::accept(); - BOOST_FOREACH(const boost::shared_ptr t, _session.get_spectrum_traces()) { + BOOST_FOREACH(const boost::shared_ptr t, _session->get_spectrum_traces()) { boost::shared_ptr spectrumTraces; if ((spectrumTraces = dynamic_pointer_cast(t))) { spectrumTraces->set_enable(false); @@ -243,13 +243,13 @@ void FftOptions::accept() //spectrumTraces->init_zoom(); spectrumTraces->set_dbv_range(_dbv_combobox->currentData().toInt()); spectrumTraces->set_enable(_en_checkbox->isChecked()); - if (_session.get_capture_state() == SigSession::Stopped && + if (_session->get_capture_state() == SigSession::Stopped && spectrumTraces->enabled()) spectrumTraces->get_spectrum_stack()->calc_fft(); } } } - _session.spectrum_rebuild(); + _session->spectrum_rebuild(); } void FftOptions::reject() diff --git a/DSView/pv/dialogs/fftoptions.h b/DSView/pv/dialogs/fftoptions.h index 2486c871..dcca5e11 100755 --- a/DSView/pv/dialogs/fftoptions.h +++ b/DSView/pv/dialogs/fftoptions.h @@ -50,7 +50,7 @@ private: public: - FftOptions(QWidget *parent, SigSession &session); + FftOptions(QWidget *parent, SigSession *session); ~FftOptions(); @@ -63,7 +63,7 @@ private slots: void len_changed(int index); private: - SigSession &_session; + SigSession *_session; uint64_t _sample_limit; QComboBox *_len_combobox; diff --git a/DSView/pv/dialogs/interval.cpp b/DSView/pv/dialogs/interval.cpp index 7ab456b7..dcb13ca5 100755 --- a/DSView/pv/dialogs/interval.cpp +++ b/DSView/pv/dialogs/interval.cpp @@ -26,7 +26,7 @@ namespace pv { namespace dialogs { -Interval::Interval(SigSession &session, QWidget *parent) : +Interval::Interval(SigSession *session, QWidget *parent) : DSDialog(parent), _session(session), _button_box(QDialogButtonBox::Ok, @@ -47,7 +47,7 @@ Interval::Interval(SigSession &session, QWidget *parent) : connect(_interval_slider, SIGNAL(valueChanged(int)), _interval_spinBox, SLOT(setValue(int))); connect(_interval_spinBox, SIGNAL(valueChanged(int)), _interval_slider, SLOT(setValue(int))); - _interval_slider->setValue(_session.get_repeat_intvl()); + _interval_slider->setValue(_session->get_repeat_intvl()); QGridLayout *glayout = new QGridLayout(this); glayout->addWidget(_interval_label, 0, 0); @@ -64,7 +64,7 @@ Interval::Interval(SigSession &session, QWidget *parent) : void Interval::accept() { using namespace Qt; - _session.set_repeat_intvl(_interval_slider->value()); + _session->set_repeat_intvl(_interval_slider->value()); QDialog::accept(); } diff --git a/DSView/pv/dialogs/interval.h b/DSView/pv/dialogs/interval.h index 86e42ade..9e3c0c40 100755 --- a/DSView/pv/dialogs/interval.h +++ b/DSView/pv/dialogs/interval.h @@ -40,14 +40,14 @@ class Interval : public DSDialog Q_OBJECT public: - Interval(SigSession &session, QWidget *parent); + Interval(SigSession *session, QWidget *parent); protected: void accept(); void reject(); private: - SigSession &_session; + SigSession *_session; QLabel *_interval_label; QSpinBox *_interval_spinBox; diff --git a/DSView/pv/dialogs/lissajousoptions.cpp b/DSView/pv/dialogs/lissajousoptions.cpp index 02c98167..aa5d53f1 100755 --- a/DSView/pv/dialogs/lissajousoptions.cpp +++ b/DSView/pv/dialogs/lissajousoptions.cpp @@ -41,7 +41,7 @@ using namespace pv::view; namespace pv { namespace dialogs { -LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) : +LissajousOptions::LissajousOptions(SigSession *session, QWidget *parent) : DSDialog(parent), _session(session), _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, @@ -63,8 +63,8 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) : _percent = new QSlider(Qt::Horizontal, this); _percent->setRange(100, 100); _percent->setEnabled(false); - if (_session.cur_samplelimits() > WellLen) { - int min = ceil(WellLen*100.0/_session.cur_samplelimits()); + if (_session->cur_samplelimits() > WellLen) { + int min = ceil(WellLen*100.0/_session->cur_samplelimits()); _percent->setEnabled(true); _percent->setRange(min, 100); _percent->setValue(min); @@ -74,7 +74,7 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) : _y_group = new QGroupBox(this); QHBoxLayout *xlayout = new QHBoxLayout(); QHBoxLayout *ylayout = new QHBoxLayout(); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { QString index_str = QString::number(dsoSig->get_index()); @@ -92,7 +92,7 @@ LissajousOptions::LissajousOptions(SigSession &session, QWidget *parent) : _y_group->setLayout(ylayout); - boost::shared_ptr lissajous = _session.get_lissajous_trace(); + boost::shared_ptr lissajous = _session->get_lissajous_trace(); if (lissajous) { _enable->setChecked(lissajous->enabled()); _percent->setValue(lissajous->percent()); @@ -180,15 +180,15 @@ void LissajousOptions::accept() } } bool enable = (xindex != -1 && yindex != -1 && _enable->isChecked()); - _session.lissajous_rebuild(enable, xindex, yindex, _percent->value()); + _session->lissajous_rebuild(enable, xindex, yindex, _percent->value()); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { dsoSig->set_show(!enable); } } - boost::shared_ptr mathTrace = _session.get_math_trace(); + boost::shared_ptr mathTrace = _session->get_math_trace(); if (mathTrace && mathTrace->enabled()) { mathTrace->set_show(!enable); } diff --git a/DSView/pv/dialogs/lissajousoptions.h b/DSView/pv/dialogs/lissajousoptions.h index b0653548..9a7e7168 100755 --- a/DSView/pv/dialogs/lissajousoptions.h +++ b/DSView/pv/dialogs/lissajousoptions.h @@ -56,7 +56,7 @@ private: static const int WellLen = SR_Kn(16); public: - LissajousOptions(SigSession &session, QWidget *parent); + LissajousOptions(SigSession *session, QWidget *parent); private: void changeEvent(QEvent *event); @@ -67,7 +67,7 @@ protected: void reject(); private: - SigSession &_session; + SigSession *_session; QCheckBox *_enable; QGroupBox *_x_group; diff --git a/DSView/pv/dialogs/mathoptions.cpp b/DSView/pv/dialogs/mathoptions.cpp index 99169c7a..95111fa5 100755 --- a/DSView/pv/dialogs/mathoptions.cpp +++ b/DSView/pv/dialogs/mathoptions.cpp @@ -41,7 +41,7 @@ using namespace pv::view; namespace pv { namespace dialogs { -MathOptions::MathOptions(SigSession &session, QWidget *parent) : +MathOptions::MathOptions(SigSession *session, QWidget *parent) : DSDialog(parent), _session(session), _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, @@ -78,7 +78,7 @@ MathOptions::MathOptions(SigSession &session, QWidget *parent) : _src2_group = new QGroupBox(this); QHBoxLayout *src1_layout = new QHBoxLayout(); QHBoxLayout *src2_layout = new QHBoxLayout(); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { QString index_str = QString::number(dsoSig->get_index()); @@ -96,7 +96,7 @@ MathOptions::MathOptions(SigSession &session, QWidget *parent) : _src2_group->setLayout(src2_layout); - boost::shared_ptr math = _session.get_math_trace(); + boost::shared_ptr math = _session->get_math_trace(); if (math) { _enable->setChecked(math->enabled()); for (QVector::const_iterator i = _src1_radio.begin(); @@ -206,7 +206,7 @@ void MathOptions::accept() bool enable = (src1 != -1 && src2 != -1 && _enable->isChecked()); boost::shared_ptr dsoSig1; boost::shared_ptr dsoSig2; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { if (dsoSig->get_index() == src1) @@ -215,7 +215,7 @@ void MathOptions::accept() dsoSig2 = dsoSig; } } - _session.math_rebuild(enable, dsoSig1, dsoSig2, type); + _session->math_rebuild(enable, dsoSig1, dsoSig2, type); } void MathOptions::reject() diff --git a/DSView/pv/dialogs/mathoptions.h b/DSView/pv/dialogs/mathoptions.h index d11afa36..ae50e7b4 100755 --- a/DSView/pv/dialogs/mathoptions.h +++ b/DSView/pv/dialogs/mathoptions.h @@ -56,7 +56,7 @@ private: static const int WellLen = SR_Kn(16); public: - MathOptions(SigSession &session, QWidget *parent); + MathOptions(SigSession *session, QWidget *parent); private: void changeEvent(QEvent *event); @@ -67,7 +67,7 @@ protected: void reject(); private: - SigSession &_session; + SigSession *_session; QCheckBox *_enable; QGroupBox *_src1_group; diff --git a/DSView/pv/dialogs/protocolexp.cpp b/DSView/pv/dialogs/protocolexp.cpp index 8956e4ad..d526a998 100755 --- a/DSView/pv/dialogs/protocolexp.cpp +++ b/DSView/pv/dialogs/protocolexp.cpp @@ -46,7 +46,7 @@ using namespace std; namespace pv { namespace dialogs { -ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) : +ProtocolExp::ProtocolExp(QWidget *parent, SigSession *session) : DSDialog(parent), _session(session), _button_box(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, @@ -64,7 +64,7 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) : _flayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow); _flayout->addRow(new QLabel(tr("Export Format: "), this), _format_combobox); - pv::data::DecoderModel* decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel* decoder_model = _session->get_decoder_model(); const boost::shared_ptr& decoder_stack = decoder_model->getDecoderStack(); if (decoder_stack) { int row_index = 0; @@ -96,7 +96,7 @@ ProtocolExp::ProtocolExp(QWidget *parent, SigSession &session) : connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); - connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } @@ -124,7 +124,7 @@ void ProtocolExp::accept() QString default_filter = _format_combobox->currentText(); QString default_name = app._userHistory.protocolExportPath + "/" + "decoder-"; - default_name += _session.get_session_time().toString("-yyMMdd-hhmmss"); + default_name += _session->get_session_time().toString("-yyMMdd-hhmmss"); QString file_name = QFileDialog::getSaveFileName( this, @@ -170,7 +170,7 @@ void ProtocolExp::accept() .arg("Time[ns]") .arg(title); - pv::data::DecoderModel* decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel* decoder_model = _session->get_decoder_model(); const boost::shared_ptr& decoder_stack = decoder_model->getDecoderStack(); int row_index = 0; Row row; diff --git a/DSView/pv/dialogs/protocolexp.h b/DSView/pv/dialogs/protocolexp.h index b978c604..e888eedf 100755 --- a/DSView/pv/dialogs/protocolexp.h +++ b/DSView/pv/dialogs/protocolexp.h @@ -54,7 +54,7 @@ class ProtocolExp : public DSDialog Q_OBJECT public: - ProtocolExp(QWidget *parent, SigSession &session); + ProtocolExp(QWidget *parent, SigSession *session); protected: void accept(); @@ -67,7 +67,7 @@ private slots: void cancel_export(); private: - SigSession &_session; + SigSession *_session; toolbars::TitleBar *_titlebar; QComboBox *_format_combobox; diff --git a/DSView/pv/dialogs/protocollist.cpp b/DSView/pv/dialogs/protocollist.cpp index 170f8eda..3b2599af 100755 --- a/DSView/pv/dialogs/protocollist.cpp +++ b/DSView/pv/dialogs/protocollist.cpp @@ -38,27 +38,27 @@ using namespace std; namespace pv { namespace dialogs { -ProtocolList::ProtocolList(QWidget *parent, SigSession &session) : +ProtocolList::ProtocolList(QWidget *parent, SigSession *session) : DSDialog(parent), _session(session), _button_box(QDialogButtonBox::Ok, Qt::Horizontal, this) { - pv::data::DecoderModel* decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel* decoder_model = _session->get_decoder_model(); _map_zoom_combobox = new QComboBox(this); _map_zoom_combobox->addItem(tr("Fit to Window")); _map_zoom_combobox->addItem(tr("Fixed")); - int cur_map_zoom = _session.get_map_zoom(); + int cur_map_zoom = _session->get_map_zoom(); if (cur_map_zoom >= _map_zoom_combobox->count()) _map_zoom_combobox->setCurrentIndex(0); else _map_zoom_combobox->setCurrentIndex(cur_map_zoom); - connect(_map_zoom_combobox, SIGNAL(currentIndexChanged(int)), &_session, SLOT(set_map_zoom(int))); + connect(_map_zoom_combobox, SIGNAL(currentIndexChanged(int)), _session, SLOT(set_map_zoom(int))); _protocol_combobox = new QComboBox(this); const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); int index = 0; BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { _protocol_combobox->addItem(d->get_name()); @@ -89,7 +89,7 @@ ProtocolList::ProtocolList(QWidget *parent, SigSession &session) : connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(_protocol_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(set_protocol(int))); set_protocol(_protocol_combobox->currentIndex()); - connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } @@ -128,7 +128,7 @@ void ProtocolList::set_protocol(int index) boost::shared_ptr decoder_stack; const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); int cur_index = 0; BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { if (index == cur_index) { @@ -139,11 +139,11 @@ void ProtocolList::set_protocol(int index) } if (!decoder_stack){ - _session.get_decoder_model()->setDecoderStack(NULL); + _session->get_decoder_model()->setDecoderStack(NULL); return; } - _session.get_decoder_model()->setDecoderStack(decoder_stack); + _session->get_decoder_model()->setDecoderStack(decoder_stack); int row_index = 0; const std::map rows = decoder_stack->get_rows_lshow(); for (std::map::const_iterator i = rows.begin(); @@ -170,7 +170,7 @@ void ProtocolList::on_row_check(bool show) boost::shared_ptr decoder_stack; const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); int cur_index = 0; BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { if (cur_index == _protocol_combobox->currentIndex()) { @@ -192,7 +192,7 @@ void ProtocolList::on_row_check(bool show) } } - _session.get_decoder_model()->setDecoderStack(decoder_stack); + _session->get_decoder_model()->setDecoderStack(decoder_stack); } } // namespace dialogs } // namespace pv diff --git a/DSView/pv/dialogs/protocollist.h b/DSView/pv/dialogs/protocollist.h index bc6a9891..1d4c68f2 100755 --- a/DSView/pv/dialogs/protocollist.h +++ b/DSView/pv/dialogs/protocollist.h @@ -48,7 +48,7 @@ class ProtocolList : public DSDialog Q_OBJECT public: - ProtocolList(QWidget *parent, SigSession &session); + ProtocolList(QWidget *parent, SigSession *session); protected: void accept(); @@ -59,7 +59,7 @@ private slots: void on_row_check(bool show); private: - SigSession &_session; + SigSession *_session; toolbars::TitleBar *_titlebar; QComboBox *_map_zoom_combobox; diff --git a/DSView/pv/dialogs/regionoptions.cpp b/DSView/pv/dialogs/regionoptions.cpp index 0a113133..12853c1d 100755 --- a/DSView/pv/dialogs/regionoptions.cpp +++ b/DSView/pv/dialogs/regionoptions.cpp @@ -37,7 +37,7 @@ namespace dialogs { const QString RegionOptions::RegionStart = QT_TR_NOOP("Start"); const QString RegionOptions::RegionEnd = QT_TR_NOOP("End"); -RegionOptions::RegionOptions(view::View *view, SigSession &session, QWidget *parent) : +RegionOptions::RegionOptions(view::View *view, SigSession *session, QWidget *parent) : DSDialog(parent), _session(session), _view(view), @@ -75,19 +75,19 @@ RegionOptions::RegionOptions(view::View *view, SigSession &session, QWidget *par setTitle(tr("Region")); connect(&_button_box, SIGNAL(accepted()), this, SLOT(set_region())); - connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } void RegionOptions::set_region() { - const uint64_t last_samples = _session.cur_samplelimits() - 1; + const uint64_t last_samples = _session->cur_samplelimits() - 1; const int index1 = _start_comboBox->currentIndex(); const int index2 = _end_comboBox->currentIndex(); uint64_t start, end; - _session.set_save_start(0); - _session.set_save_end(last_samples); + _session->set_save_start(0); + _session->set_save_end(last_samples); if (index1 == 0) { start = 0; @@ -105,8 +105,8 @@ void RegionOptions::set_region() if (end > last_samples) end = last_samples; - _session.set_save_start(min(start, end)); - _session.set_save_end(max(start, end)); + _session->set_save_start(min(start, end)); + _session->set_save_end(max(start, end)); QDialog::accept(); } diff --git a/DSView/pv/dialogs/regionoptions.h b/DSView/pv/dialogs/regionoptions.h index 097baff7..a0ec9554 100755 --- a/DSView/pv/dialogs/regionoptions.h +++ b/DSView/pv/dialogs/regionoptions.h @@ -52,13 +52,13 @@ private: static const QString RegionEnd; public: - RegionOptions(view::View *view, SigSession &session, QWidget *parent = 0); + RegionOptions(view::View *view, SigSession *session, QWidget *parent = 0); private slots: void set_region(); private: - SigSession &_session; + SigSession *_session; view::View *_view; QComboBox *_start_comboBox; diff --git a/DSView/pv/dialogs/search.cpp b/DSView/pv/dialogs/search.cpp index 86e69dda..74568d7f 100755 --- a/DSView/pv/dialogs/search.cpp +++ b/DSView/pv/dialogs/search.cpp @@ -30,7 +30,7 @@ namespace pv { namespace dialogs { -Search::Search(QWidget *parent, SigSession &session, std::map pattern) : +Search::Search(QWidget *parent, SigSession *session, std::map pattern) : DSDialog(parent), _session(session) { @@ -51,7 +51,7 @@ Search::Search(QWidget *parent, SigSession &session, std::map int index = 0; BOOST_FOREACH(const boost::shared_ptr sig, - _session.get_signals()) { + _session->get_signals()) { assert(sig); boost::shared_ptr logic_sig; if ((logic_sig = boost::dynamic_pointer_cast(sig))) { @@ -86,7 +86,7 @@ Search::Search(QWidget *parent, SigSession &session, std::map connect(&search_buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(&search_buttonBox, SIGNAL(rejected()), this, SLOT(reject())); - connect(_session.get_device().get(), SIGNAL(device_updated()), this, SLOT(reject())); + connect(_session->get_device(), SIGNAL(device_updated()), this, SLOT(reject())); } Search::~Search() @@ -112,7 +112,7 @@ std::map Search::get_pattern() int index = 0; BOOST_FOREACH(const boost::shared_ptr sig, - _session.get_signals()) { + _session->get_signals()) { assert(sig); boost::shared_ptr logic_sig; if ((logic_sig = boost::dynamic_pointer_cast(sig))) { diff --git a/DSView/pv/dialogs/search.h b/DSView/pv/dialogs/search.h index d1f7950a..29c3d5a4 100755 --- a/DSView/pv/dialogs/search.h +++ b/DSView/pv/dialogs/search.h @@ -45,7 +45,7 @@ class Search : public DSDialog public: - Search(QWidget *parent, SigSession &session, std::map pattern); + Search(QWidget *parent, SigSession *session, std::map pattern); ~Search(); std::map get_pattern(); @@ -59,7 +59,7 @@ private slots: void format(); private: - SigSession &_session; + SigSession *_session; toolbars::TitleBar *_titlebar; QVector _search_lineEdit_vec; diff --git a/DSView/pv/dialogs/storeprogress.cpp b/DSView/pv/dialogs/storeprogress.cpp index 19d0329e..7c0b31de 100755 --- a/DSView/pv/dialogs/storeprogress.cpp +++ b/DSView/pv/dialogs/storeprogress.cpp @@ -34,7 +34,7 @@ namespace pv { namespace dialogs { -StoreProgress::StoreProgress(SigSession &session, QWidget *parent) : +StoreProgress::StoreProgress(SigSession *session, QWidget *parent) : DSDialog(parent), _store_session(session) { @@ -155,7 +155,7 @@ void StoreProgress::accept() void StoreProgress::timeout() { if (_done) { - _store_session.session().set_saving(false); + _store_session.session()->set_saving(false); save_done(); close(); } else { diff --git a/DSView/pv/dialogs/storeprogress.h b/DSView/pv/dialogs/storeprogress.h index 63d7c013..a7077142 100755 --- a/DSView/pv/dialogs/storeprogress.h +++ b/DSView/pv/dialogs/storeprogress.h @@ -44,7 +44,7 @@ class StoreProgress : public DSDialog Q_OBJECT public: - StoreProgress(SigSession &session, + StoreProgress(SigSession *session, QWidget *parent = 0); virtual ~StoreProgress(); diff --git a/DSView/pv/dialogs/waitingdialog.cpp b/DSView/pv/dialogs/waitingdialog.cpp index c901cbdf..6272227c 100755 --- a/DSView/pv/dialogs/waitingdialog.cpp +++ b/DSView/pv/dialogs/waitingdialog.cpp @@ -43,14 +43,14 @@ namespace dialogs { const QString WaitingDialog::TIPS_WAIT = "Waiting"; const QString WaitingDialog::TIPS_FINISHED = "Finished!"; -WaitingDialog::WaitingDialog(QWidget *parent, SigSession &session, int key) : +WaitingDialog::WaitingDialog(QWidget *parent, SigSession *session, int key) : DSDialog(parent), _key(key), _session(session), _button_box(QDialogButtonBox::Abort, Qt::Horizontal, this) { - _dev_inst = _session.get_device(); + _dev_inst = _session->get_device(); this->setFixedSize((GIF_WIDTH+2*TIP_WIDTH)*1.2, (GIF_HEIGHT+2*TIP_HEIGHT)*4); this->setWindowOpacity(0.7); @@ -79,7 +79,7 @@ WaitingDialog::WaitingDialog(QWidget *parent, SigSession &session, int key) : connect(timer, SIGNAL(timeout()), this, SLOT(changeText())); connect(&_button_box, SIGNAL(accepted()), this, SLOT(accept())); connect(&_button_box, SIGNAL(rejected()), this, SLOT(reject())); - connect(_dev_inst.get(), SIGNAL(device_updated()), this, SLOT(stop())); + connect(_dev_inst, SIGNAL(device_updated()), this, SLOT(stop())); QVBoxLayout *mlayout = new QVBoxLayout(); @@ -186,7 +186,7 @@ void WaitingDialog::changeText() g_variant_unref(gvar); if (zero_fgain) { boost::shared_ptr dsoSig; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { if ((dsoSig = dynamic_pointer_cast(s))) dsoSig->set_enable(dsoSig->get_index() == 0); diff --git a/DSView/pv/dialogs/waitingdialog.h b/DSView/pv/dialogs/waitingdialog.h index fd14615a..e8fb2474 100755 --- a/DSView/pv/dialogs/waitingdialog.h +++ b/DSView/pv/dialogs/waitingdialog.h @@ -35,6 +35,8 @@ #include "../toolbars/titlebar.h" #include "dsdialog.h" +using namespace pv::device; + namespace pv { namespace dialogs { @@ -53,7 +55,7 @@ private: static const QString TIPS_FINISHED; public: - WaitingDialog(QWidget *parent, SigSession &session, int key); + WaitingDialog(QWidget *parent, SigSession *session, int key); int start(); protected: @@ -66,8 +68,8 @@ private slots: private: int _key; - SigSession &_session; - boost::shared_ptr _dev_inst; + SigSession *_session; + DevInst* _dev_inst; toolbars::TitleBar *_titlebar; QDialogButtonBox _button_box; diff --git a/DSView/pv/dock/dsotriggerdock.cpp b/DSView/pv/dock/dsotriggerdock.cpp index 08bc64b6..d11e961c 100755 --- a/DSView/pv/dock/dsotriggerdock.cpp +++ b/DSView/pv/dock/dsotriggerdock.cpp @@ -44,7 +44,7 @@ using namespace std; namespace pv { namespace dock { -DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession &session) : +DsoTriggerDock::DsoTriggerDock(QWidget *parent, SigSession *session) : QScrollArea(parent), _session(session) { @@ -222,7 +222,7 @@ void DsoTriggerDock::auto_trig(int index) void DsoTriggerDock::pos_changed(int pos) { int ret; - ret = _session.get_device()->set_config(NULL, NULL, + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_HORIZ_TRIGGERPOS, g_variant_new_byte((uint8_t)pos)); if (!ret) { @@ -247,7 +247,7 @@ void DsoTriggerDock::hold_changed(int hold) _holdoff_slider->setRange(0, 999); } holdoff = _holdoff_slider->value() * _holdoff_comboBox->currentData().toDouble() / 10; - ret = _session.get_device()->set_config(NULL, NULL, + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_TRIGGER_HOLDOFF, g_variant_new_uint64(holdoff)); @@ -264,7 +264,7 @@ void DsoTriggerDock::hold_changed(int hold) void DsoTriggerDock::margin_changed(int margin) { int ret; - ret = _session.get_device()->set_config(NULL, NULL, + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_TRIGGER_MARGIN, g_variant_new_byte(margin)); if (!ret) { @@ -282,7 +282,7 @@ void DsoTriggerDock::source_changed() int id = _source_group->checkedId(); int ret; - ret = _session.get_device()->set_config(NULL, NULL, + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_TRIGGER_SOURCE, g_variant_new_byte(id)); if (!ret) { @@ -300,7 +300,7 @@ void DsoTriggerDock::channel_changed(int ch) (void)ch; int ret; - ret = _session.get_device()->set_config(NULL, NULL, + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_TRIGGER_CHANNEL, g_variant_new_byte(_channel_comboBox->currentData().toInt())); if (!ret) { @@ -318,7 +318,7 @@ void DsoTriggerDock::type_changed() int id = _type_group->checkedId(); int ret; - ret = _session.get_device()->set_config(NULL, NULL, + ret = _session->get_device()->set_config(NULL, NULL, SR_CONF_TRIGGER_SLOPE, g_variant_new_byte(id)); if (!ret) { @@ -333,7 +333,7 @@ void DsoTriggerDock::type_changed() void DsoTriggerDock::device_change() { - if (_session.get_device()->name() != "DSLogic") { + if (_session->get_device()->name() != "DSLogic") { _position_spinBox->setDisabled(true); _position_slider->setDisabled(true); } else { @@ -344,7 +344,7 @@ void DsoTriggerDock::device_change() void DsoTriggerDock::init() { - if (_session.get_device()->name().contains("virtual")) { + if (_session->get_device()->name().contains("virtual")) { foreach(QAbstractButton * btn, _source_group->buttons()) btn->setDisabled(true); foreach(QAbstractButton * btn, _type_group->buttons()) @@ -368,7 +368,7 @@ void DsoTriggerDock::init() } // TRIGGERPOS - GVariant* gvar = _session.get_device()->get_config(NULL, NULL, + GVariant* gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_HORIZ_TRIGGERPOS); if (gvar != NULL) { uint16_t pos = g_variant_get_byte(gvar); @@ -376,7 +376,7 @@ void DsoTriggerDock::init() _position_slider->setValue(pos); } - gvar = _session.get_device()->get_config(NULL, NULL, + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_SOURCE); if (gvar != NULL) { uint8_t src = g_variant_get_byte(gvar); @@ -387,13 +387,13 @@ void DsoTriggerDock::init() // setup _channel_comboBox disconnect(_channel_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(channel_changed(int))); _channel_comboBox->clear(); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { _channel_comboBox->addItem(dsoSig->get_name(), QVariant::fromValue(dsoSig->get_index())); } } - gvar = _session.get_device()->get_config(NULL, NULL, + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_CHANNEL); if (gvar != NULL) { uint8_t src = g_variant_get_byte(gvar); @@ -407,7 +407,7 @@ void DsoTriggerDock::init() } connect(_channel_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(channel_changed(int))); - gvar = _session.get_device()->get_config(NULL, NULL, + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_SLOPE); if (gvar != NULL) { uint8_t slope = g_variant_get_byte(gvar); @@ -417,7 +417,7 @@ void DsoTriggerDock::init() disconnect(_holdoff_slider, SIGNAL(valueChanged(int)), this, SLOT(hold_changed(int))); disconnect(_holdoff_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hold_changed(int))); - gvar = _session.get_device()->get_config(NULL, NULL, + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_HOLDOFF); if (gvar != NULL) { uint64_t holdoff = g_variant_get_uint64(gvar); @@ -439,7 +439,7 @@ void DsoTriggerDock::init() connect(_holdoff_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(hold_changed(int))); disconnect(_margin_slider, SIGNAL(valueChanged(int)), this, SLOT(margin_changed(int))); - gvar = _session.get_device()->get_config(NULL, NULL, + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TRIGGER_MARGIN); if (gvar != NULL) { uint8_t margin = g_variant_get_byte(gvar); diff --git a/DSView/pv/dock/dsotriggerdock.h b/DSView/pv/dock/dsotriggerdock.h index b0971b72..4688577e 100755 --- a/DSView/pv/dock/dsotriggerdock.h +++ b/DSView/pv/dock/dsotriggerdock.h @@ -44,7 +44,7 @@ class DsoTriggerDock : public QScrollArea Q_OBJECT public: - DsoTriggerDock(QWidget *parent, SigSession &session); + DsoTriggerDock(QWidget *parent, SigSession *session); ~DsoTriggerDock(); void paintEvent(QPaintEvent *); @@ -75,7 +75,7 @@ private slots: private: private: - SigSession &_session; + SigSession *_session; QWidget *_widget; diff --git a/DSView/pv/dock/measuredock.cpp b/DSView/pv/dock/measuredock.cpp index fc7644f6..77166789 100755 --- a/DSView/pv/dock/measuredock.cpp +++ b/DSView/pv/dock/measuredock.cpp @@ -50,7 +50,7 @@ namespace dock { using namespace pv::view; -MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession &session) : +MeasureDock::MeasureDock(QWidget *parent, View &view, SigSession *session) : QScrollArea(parent), _session(session), _view(view) @@ -212,7 +212,7 @@ void MeasureDock::refresh() void MeasureDock::reload() { - if (_session.get_device()->dev_inst()->mode == LOGIC) + if (_session->get_device()->dev_inst()->mode == LOGIC) _edge_groupBox->setDisabled(false); else _edge_groupBox->setDisabled(true); @@ -598,7 +598,7 @@ void MeasureDock::update_edge() if (start_ret && end_ret) { uint64_t rising_edges; uint64_t falling_edges; - const std::vector< boost::shared_ptr > sigs(_session.get_signals()); + const std::vector< boost::shared_ptr > sigs(_session->get_signals()); for(size_t i = 0; i < sigs.size(); i++) { const boost::shared_ptr s(sigs[i]); boost::shared_ptr logicSig; @@ -650,7 +650,7 @@ QComboBox* MeasureDock::create_probe_selector(QWidget *parent) void MeasureDock::update_probe_selector(QComboBox *selector) { selector->clear(); - const std::vector< boost::shared_ptr > sigs(_session.get_signals()); + const std::vector< boost::shared_ptr > sigs(_session->get_signals()); for(size_t i = 0; i < sigs.size(); i++) { const boost::shared_ptr s(sigs[i]); assert(s); diff --git a/DSView/pv/dock/measuredock.h b/DSView/pv/dock/measuredock.h index c9f9beeb..379b1d38 100755 --- a/DSView/pv/dock/measuredock.h +++ b/DSView/pv/dock/measuredock.h @@ -61,7 +61,7 @@ private: static const int Max_Measure_Limits = 16; public: - MeasureDock(QWidget *parent, pv::view::View &view, SigSession &session); + MeasureDock(QWidget *parent, pv::view::View &view, SigSession *session); ~MeasureDock(); void paintEvent(QPaintEvent *); @@ -101,7 +101,7 @@ public slots: void refresh(); private: - SigSession &_session; + SigSession *_session; view::View &_view; QWidget *_widget; diff --git a/DSView/pv/dock/protocoldock.cpp b/DSView/pv/dock/protocoldock.cpp index c4709222..48e04900 100755 --- a/DSView/pv/dock/protocoldock.cpp +++ b/DSView/pv/dock/protocoldock.cpp @@ -56,7 +56,7 @@ namespace pv { namespace dock { -ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &session) : +ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession *session) : QScrollArea(parent), _session(session), _view(view), @@ -126,7 +126,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio //dn_title_layout->addStretch(1); _table_view = new QTableView(_dn_widget); - _table_view->setModel(_session.get_decoder_model()); + _table_view->setModel(_session->get_decoder_model()); _table_view->setAlternatingRowColors(true); _table_view->setShowGrid(false); _table_view->horizontalHeader()->setStretchLastSection(true); @@ -197,7 +197,7 @@ ProtocolDock::ProtocolDock(QWidget *parent, view::View &view, SigSession &sessio connect(_del_all_button, SIGNAL(clicked()),this, SLOT(on_del_all_protocol())); - connect(&_session, SIGNAL(decode_done()), this, SLOT(update_model())); + connect(_session, SIGNAL(decode_done()), this, SLOT(update_model())); connect(this, SIGNAL(protocol_updated()), this, SLOT(update_model())); connect(_table_view, SIGNAL(clicked(QModelIndex)), this, SLOT(item_clicked(QModelIndex))); connect(_table_view->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(column_resize(int, int, int))); @@ -305,7 +305,7 @@ void ProtocolDock::on_add_protocol() void ProtocolDock::add_protocol(bool silent) { - if (_session.get_device()->dev_inst()->mode != LOGIC) { + if (_session->get_device()->dev_inst()->mode != LOGIC) { MsgBox::Show(NULL, "Protocol Analyzer\nProtocol Analyzer is only valid in Digital Mode!", this); return; } @@ -316,7 +316,7 @@ void ProtocolDock::add_protocol(bool silent) DecoderStatus *dstatus = new DecoderStatus(); dstatus->m_format = (int)DecoderDataFormat::hex; - if (_session.add_decoder(decoder, silent, dstatus)) + if (_session->add_decoder(decoder, silent, dstatus)) { //crate item layer QString protocolName = _protocol_combobox->currentText(); @@ -333,7 +333,7 @@ void ProtocolDock::add_protocol(bool silent) } //progress connection - const std::vector> decode_sigs(_session.get_decode_signals()); + const std::vector> decode_sigs(_session->get_decode_signals()); connect(decode_sigs.back().get(), SIGNAL(decoded_progress(int)), this, SLOT(decoded_progress(int))); @@ -360,7 +360,7 @@ void ProtocolDock::del_all_protocol() for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++) { DESTROY_QT_LATER((*it)); //destory control - _session.remove_decode_signal(0); + _session->remove_decode_signal(0); } _protocol_items.clear(); protocol_updated(); @@ -374,7 +374,7 @@ void ProtocolDock::decoded_progress(int progress) int pg = 0; QString err=""; const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); int index = 0; BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { @@ -409,13 +409,13 @@ void ProtocolDock::set_model() { pv::dialogs::ProtocolList *protocollist_dlg = new pv::dialogs::ProtocolList(this, _session); protocollist_dlg->exec(); - resize_table_view(_session.get_decoder_model()); - _model_proxy.setSourceModel(_session.get_decoder_model()); + resize_table_view(_session->get_decoder_model()); + _model_proxy.setSourceModel(_session->get_decoder_model()); search_done(); // clear mark_index of all DecoderStacks const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { d->decoder()->set_mark_index(-1); } @@ -423,9 +423,9 @@ void ProtocolDock::set_model() void ProtocolDock::update_model() { - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); if (decode_sigs.size() == 0) decoder_model->setDecoderStack(NULL); else if (!decoder_model->getDecoderStack()) @@ -466,18 +466,18 @@ void ProtocolDock::resize_table_view(data::DecoderModel* decoder_model) void ProtocolDock::item_clicked(const QModelIndex &index) { - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); boost::shared_ptr decoder_stack = decoder_model->getDecoderStack(); if (decoder_stack) { pv::data::decode::Annotation ann; if (decoder_stack->list_annotation(ann, index.column(), index.row())) { const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { d->decoder()->set_mark_index(-1); } decoder_stack->set_mark_index((ann.start_sample()+ann.end_sample())/2); - _session.show_region(ann.start_sample(), ann.end_sample(), false); + _session->show_region(ann.start_sample(), ann.end_sample(), false); } } _table_view->resizeRowToContents(index.row()); @@ -524,7 +524,7 @@ void ProtocolDock::column_resize(int index, int old_size, int new_size) (void)index; (void)old_size; (void)new_size; - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); if (decoder_model->getDecoderStack()) { int top_row = _table_view->rowAt(0); int bom_row = _table_view->rowAt(_table_view->height()); @@ -544,7 +544,7 @@ void ProtocolDock::export_table_view() void ProtocolDock::nav_table_view() { uint64_t row_index = 0; - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); boost::shared_ptr decoder_stack = decoder_model->getDecoderStack(); if (decoder_stack) { uint64_t offset = _view.offset() * (decoder_stack->samplerate() * _view.scale()); @@ -565,7 +565,7 @@ void ProtocolDock::nav_table_view() pv::data::decode::Annotation ann; decoder_stack->list_annotation(ann, index.column(), index.row()); const std::vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); BOOST_FOREACH(boost::shared_ptr d, decode_sigs) { d->decoder()->set_mark_index(-1); } @@ -591,7 +591,7 @@ void ProtocolDock::search_pre() int i = 0; uint64_t rowCount = _model_proxy.rowCount(); QModelIndex matchingIndex; - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); boost::shared_ptr decoder_stack = decoder_model->getDecoderStack(); do { _cur_search_index--; @@ -647,7 +647,7 @@ void ProtocolDock::search_nxt() int i = 0; uint64_t rowCount = _model_proxy.rowCount(); QModelIndex matchingIndex; - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); boost::shared_ptr decoder_stack = decoder_model->getDecoderStack(); do { _cur_search_index++; @@ -711,7 +711,7 @@ void ProtocolDock::search_update() if (!_search_edited) return; - pv::data::DecoderModel *decoder_model = _session.get_decoder_model(); + pv::data::DecoderModel *decoder_model = _session->get_decoder_model(); boost::shared_ptr decoder_stack = decoder_model->getDecoderStack(); if (!decoder_stack) return; @@ -746,7 +746,7 @@ void ProtocolDock::OnProtocolSetting(void *handle){ int dex = 0; for (auto it = _protocol_items.begin(); it != _protocol_items.end(); it++){ if ((*it) == handle){ - _session.rst_decoder(dex); + _session->rst_decoder(dex); protocol_updated(); break; } @@ -764,7 +764,7 @@ void ProtocolDock::OnProtocolDelete(void *handle){ if ((*it) == handle){ DESTROY_QT_LATER(*it); _protocol_items.remove(dex); - _session.remove_decode_signal(dex); + _session->remove_decode_signal(dex); protocol_updated(); break; } diff --git a/DSView/pv/dock/protocoldock.h b/DSView/pv/dock/protocoldock.h index 8b7a1a39..1e7e9ded 100755 --- a/DSView/pv/dock/protocoldock.h +++ b/DSView/pv/dock/protocoldock.h @@ -64,7 +64,7 @@ public: static const uint64_t ProgressRows = 100000; public: - ProtocolDock(QWidget *parent, view::View &view, SigSession &session); + ProtocolDock(QWidget *parent, view::View &view, SigSession *session); ~ProtocolDock(); void del_all_protocol(); @@ -109,7 +109,7 @@ private: void resize_table_view(data::DecoderModel *decoder_model); private: - SigSession &_session; + SigSession *_session; view::View &_view; QSortFilterProxyModel _model_proxy; double _cur_search_index; diff --git a/DSView/pv/dock/searchdock.cpp b/DSView/pv/dock/searchdock.cpp index 1372ca78..87b2cee3 100755 --- a/DSView/pv/dock/searchdock.cpp +++ b/DSView/pv/dock/searchdock.cpp @@ -50,7 +50,7 @@ namespace dock { using namespace pv::view; using namespace pv::widgets; -SearchDock::SearchDock(QWidget *parent, View &view, SigSession &session) : +SearchDock::SearchDock(QWidget *parent, View &view, SigSession *session) : QWidget(parent), _session(session), _view(view) @@ -130,7 +130,7 @@ void SearchDock::on_previous() bool ret; int64_t last_pos; bool last_hit; - const boost::shared_ptr snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC)); + const boost::shared_ptr snapshot(_session->get_snapshot(SR_CHANNEL_LOGIC)); assert(snapshot); const boost::shared_ptr logic_snapshot = boost::dynamic_pointer_cast(snapshot); @@ -192,7 +192,7 @@ void SearchDock::on_next() { bool ret; int64_t last_pos; - const boost::shared_ptr snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC)); + const boost::shared_ptr snapshot(_session->get_snapshot(SR_CHANNEL_LOGIC)); assert(snapshot); const boost::shared_ptr logic_snapshot = boost::dynamic_pointer_cast(snapshot); diff --git a/DSView/pv/dock/searchdock.h b/DSView/pv/dock/searchdock.h index 0f68daad..6e940bb3 100755 --- a/DSView/pv/dock/searchdock.h +++ b/DSView/pv/dock/searchdock.h @@ -63,7 +63,7 @@ class SearchDock : public QWidget Q_OBJECT public: - SearchDock(QWidget *parent, pv::view::View &view, SigSession &session); + SearchDock(QWidget *parent, pv::view::View &view, SigSession *session); ~SearchDock(); void paintEvent(QPaintEvent *); @@ -78,7 +78,7 @@ public slots: void on_set(); private: - SigSession &_session; + SigSession *_session; view::View &_view; std::map _pattern; diff --git a/DSView/pv/dock/triggerdock.cpp b/DSView/pv/dock/triggerdock.cpp index e38ea7dc..d69b7828 100755 --- a/DSView/pv/dock/triggerdock.cpp +++ b/DSView/pv/dock/triggerdock.cpp @@ -40,13 +40,13 @@ namespace dock { const int TriggerDock::MinTrigPosition = 1; -TriggerDock::TriggerDock(QWidget *parent, SigSession &session) : +TriggerDock::TriggerDock(QWidget *parent, SigSession *session) : QScrollArea(parent), _session(session) { _cur_ch_num = 16; - if (_session.get_device()) { - GVariant *gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_TOTAL_CH_NUM); + if (_session->get_device()) { + GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TOTAL_CH_NUM); if (gvar != NULL) { _cur_ch_num = g_variant_get_int16(gvar); g_variant_unref(gvar); @@ -180,9 +180,9 @@ void TriggerDock::simple_trigger() void TriggerDock::adv_trigger() { - if (_session.get_device()->name() == "DSLogic") { + if (_session->get_device()->name() == "DSLogic") { bool stream = false; - GVariant *gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_STREAM); + GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar != NULL) { stream = g_variant_get_boolean(gvar); g_variant_unref(gvar); @@ -248,20 +248,20 @@ void TriggerDock::device_updated() bool stream = false; uint8_t maxRange; uint64_t sample_limits; - GVariant *gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_HW_DEPTH); + GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_HW_DEPTH); if (gvar != NULL) { hw_depth = g_variant_get_uint64(gvar); g_variant_unref(gvar); - if (_session.get_device()->dev_inst()->mode == LOGIC) { + if (_session->get_device()->dev_inst()->mode == LOGIC) { - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_STREAM); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar != NULL) { stream = g_variant_get_boolean(gvar); g_variant_unref(gvar); } - sample_limits = _session.get_device()->get_sample_limit(); + sample_limits = _session->get_device()->get_sample_limit(); if (stream) maxRange = 1; else if (hw_depth >= sample_limits) @@ -271,7 +271,7 @@ void TriggerDock::device_updated() _position_spinBox->setRange(MinTrigPosition, maxRange); _position_slider->setRange(MinTrigPosition, maxRange); - if (_session.get_device()->name().contains("virtual") || + if (_session->get_device()->name().contains("virtual") || stream) { _simple_radioButton->setChecked(true); simple_trigger(); @@ -279,7 +279,7 @@ void TriggerDock::device_updated() } } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_TOTAL_CH_NUM); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TOTAL_CH_NUM); if (gvar != NULL) { int ch_num = g_variant_get_int16(gvar); g_variant_unref(gvar); diff --git a/DSView/pv/dock/triggerdock.h b/DSView/pv/dock/triggerdock.h index 3dd19e68..336f5dc7 100755 --- a/DSView/pv/dock/triggerdock.h +++ b/DSView/pv/dock/triggerdock.h @@ -57,7 +57,7 @@ private: static const int MinTrigPosition; public: - TriggerDock(QWidget *parent, SigSession &session); + TriggerDock(QWidget *parent, SigSession *session); ~TriggerDock(); void paintEvent(QPaintEvent *); @@ -95,7 +95,7 @@ public slots: private: private: - SigSession &_session; + SigSession *_session; int _cur_ch_num; QWidget *_widget; diff --git a/DSView/pv/mainframe.cpp b/DSView/pv/mainframe.cpp index 7c83b53b..fca633f7 100755 --- a/DSView/pv/mainframe.cpp +++ b/DSView/pv/mainframe.cpp @@ -51,8 +51,7 @@ namespace pv { -MainFrame::MainFrame(DeviceManager &device_manager, - const char *open_file_name) +MainFrame::MainFrame() { setAttribute(Qt::WA_TranslucentBackground); // Make this a borderless window which can't @@ -83,7 +82,7 @@ MainFrame::MainFrame(DeviceManager &device_manager, _titleBar = new toolbars::TitleBar(true, this); // MainWindow - _mainWindow = new MainWindow(device_manager, open_file_name, this); + _mainWindow = new MainWindow(this); _mainWindow->setWindowFlags(Qt::Widget); _titleBar->setTitle(_mainWindow->windowTitle()); diff --git a/DSView/pv/mainframe.h b/DSView/pv/mainframe.h index 7e6711ce..e04ac0ee 100755 --- a/DSView/pv/mainframe.h +++ b/DSView/pv/mainframe.h @@ -30,8 +30,7 @@ #include namespace pv { - -class DeviceManager; + class MainWindow; namespace toolbars { @@ -66,8 +65,7 @@ public: }borderTypes; public: - MainFrame(DeviceManager &device_manager, - const char *open_file_name = NULL); + MainFrame(); void readSettings(); diff --git a/DSView/pv/mainwindow.cpp b/DSView/pv/mainwindow.cpp index 029d1e0c..7cadf548 100755 --- a/DSView/pv/mainwindow.cpp +++ b/DSView/pv/mainwindow.cpp @@ -92,6 +92,7 @@ #include #include "../ui/msgbox.h" #include "config/appconfig.h" +#include "appcontrol.h" using boost::shared_ptr; using boost::dynamic_pointer_cast; @@ -100,30 +101,32 @@ using std::vector; namespace pv { -MainWindow::MainWindow(DeviceManager &device_manager, - const char *open_file_name, - QWidget *parent) : +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), - _device_manager(device_manager), - _session(device_manager), _hot_detach(false), _msg(NULL) { + _control = AppControl::Instance(); + setup_ui(); setContextMenuPolicy(Qt::NoContextMenu); + /* if (open_file_name) { qDebug("Open file: %s", open_file_name); const QString s(QString::fromUtf8(open_file_name)); - QMetaObject::invokeMethod(this, "load_file", + QMetaObject::invokeMethod(this, "on_load_file", Qt::QueuedConnection, Q_ARG(QString, s)); } + */ } void MainWindow::setup_ui() { + SigSession *_session = _control->GetSession(); + setObjectName(QString::fromUtf8("MainWindow")); setContentsMargins(0,0,0,0); layout()->setMargin(0); @@ -236,7 +239,7 @@ void MainWindow::setup_ui() _search_dock->installEventFilter(this); // Populate the device list and select the initially selected device - _session.set_default_device(boost::bind(&MainWindow::session_error, this, + _session->set_default_device(boost::bind(&MainWindow::session_error, this, QString(tr("Set Default Device failed")), _1)); // defaut language @@ -249,22 +252,22 @@ void MainWindow::setup_ui() // update device update_device_list(); - _session.start_hotplug_proc(boost::bind(&MainWindow::session_error, this, + _session->start_hotplug_proc(boost::bind(&MainWindow::session_error, this, QString(tr("Hotplug failed")), _1)); retranslateUi(); // Setup _session events - connect(&_session, SIGNAL(capture_state_changed(int)), this, SLOT(capture_state_changed(int))); - connect(&_session, SIGNAL(device_attach()), this, SLOT(device_attach()), Qt::QueuedConnection); - connect(&_session, SIGNAL(device_detach()), this, SLOT(device_detach()), Qt::QueuedConnection); - connect(&_session, SIGNAL(session_error()), this, SLOT(on_show_error()), Qt::QueuedConnection); - connect(&_session, SIGNAL(session_save()), this, SLOT(session_save())); - connect(&_session, SIGNAL(data_updated()), _measure_widget, SLOT(reCalc())); - connect(&_session, SIGNAL(repeat_resume()), this, SLOT(repeat_resume())); - connect(&_session, SIGNAL(update_capture()), _view, SLOT(update_hori_res()), Qt::DirectConnection); - connect(&_session, SIGNAL(cur_snap_samplerate_changed()), _measure_widget, SLOT(cursor_update())); + connect(_session, SIGNAL(capture_state_changed(int)), this, SLOT(capture_state_changed(int))); + connect(_session, SIGNAL(device_attach()), this, SLOT(device_attach()), Qt::QueuedConnection); + connect(_session, SIGNAL(device_detach()), this, SLOT(device_detach()), Qt::QueuedConnection); + connect(_session, SIGNAL(session_error()), this, SLOT(on_show_error()), Qt::QueuedConnection); + connect(_session, SIGNAL(session_save()), this, SLOT(session_save())); + connect(_session, SIGNAL(data_updated()), _measure_widget, SLOT(reCalc())); + connect(_session, SIGNAL(repeat_resume()), this, SLOT(repeat_resume())); + connect(_session, SIGNAL(update_capture()), _view, SLOT(update_hori_res()), Qt::DirectConnection); + connect(_session, SIGNAL(cur_snap_samplerate_changed()), _measure_widget, SLOT(cursor_update())); //view connect(_view, SIGNAL(cursor_update()), _measure_widget, SLOT(cursor_update())); @@ -342,8 +345,10 @@ void MainWindow::update_device_list() AppConfig &app = AppConfig::Instance(); + SigSession *_session = _control->GetSession(); + switchLanguage(app._frameOptions.language); - _session.stop_capture(); + _session->stop_capture(); _view->reload(); _trigger_widget->device_updated(); @@ -351,13 +356,15 @@ void MainWindow::update_device_list() _trig_bar->reload(); - boost::shared_ptr selected_device = _session.get_device(); + DeviceManager &_device_manager = _control->GetDeviceManager(); + + DevInst *selected_device = _session->get_device(); _device_manager.add_device(selected_device); - _session.init_signals(); + _session->init_signals(); _sampling_bar->set_device_list(_device_manager.devices(), selected_device); - boost::shared_ptr file_dev; - if((file_dev = dynamic_pointer_cast(selected_device))) { + File *file_dev = NULL; + if((file_dev = dynamic_cast(selected_device))) { // check version if (selected_device->dev_inst()->mode == LOGIC) { GVariant* gvar = selected_device->get_config(NULL, NULL, SR_CONF_FILE_VERSION); @@ -385,7 +392,7 @@ void MainWindow::update_device_list() // load data const QString errorMessage( QString(tr("Failed to capture file data!"))); - _session.start_capture(true, boost::bind(&MainWindow::session_error, this, + _session->start_capture(true, boost::bind(&MainWindow::session_error, this, errorMessage, _1)); } @@ -457,20 +464,23 @@ void MainWindow::update_device_list() void MainWindow::on_device_updated_reload() { + SigSession *_session = _control->GetSession(); _trigger_widget->device_updated(); - _session.reload(); + _session->reload(); _measure_widget->reload(); } void MainWindow::on_load_file(QString file_name) { + SigSession *_session = _control->GetSession(); + try { - if (strncmp(_session.get_device()->name().toUtf8(), "virtual", 7)) + if (strncmp(_session->get_device()->name().toUtf8(), "virtual", 7)) session_save(); - _session.set_file(file_name); + _session->set_file(file_name); } catch(QString e) { show_session_error(tr("Failed to load ") + file_name, e); - _session.set_default_device(boost::bind(&MainWindow::session_error, this, + _session->set_default_device(boost::bind(&MainWindow::session_error, this, QString(tr("Set Default Device failed")), _1)); update_device_list(); return; @@ -494,23 +504,27 @@ void MainWindow::show_session_error( void MainWindow::device_attach() { - _session.get_device()->device_updated(); - //_session.stop_hot_plug_proc(); + SigSession *_session = _control->GetSession(); - _session.set_repeating(false); - _session.stop_capture(); + _session->get_device()->device_updated(); + //_session->stop_hot_plug_proc(); + + _session->set_repeating(false); + _session->stop_capture(); _sampling_bar->set_sampling(false); - _session.capture_state_changed(SigSession::Stopped); + _session->capture_state_changed(SigSession::Stopped); struct sr_dev_driver **const drivers = sr_driver_list(); struct sr_dev_driver **driver; + DeviceManager &_device_manager = _control->GetDeviceManager(); + for (driver = drivers; *driver; driver++) if (*driver) _device_manager.driver_scan(*driver); - _session.set_default_device(boost::bind(&MainWindow::session_error, this, + _session->set_default_device(boost::bind(&MainWindow::session_error, this, QString(tr("Set Default Device failed")), _1)); update_device_list(); @@ -518,21 +532,23 @@ void MainWindow::device_attach() void MainWindow::device_detach() { - _session.get_device()->device_updated(); - //_session.stop_hot_plug_proc(); + SigSession *_session = _control->GetSession(); - _session.set_repeating(false); - _session.stop_capture(); + _session->get_device()->device_updated(); + //_session->stop_hot_plug_proc(); + + _session->set_repeating(false); + _session->stop_capture(); _sampling_bar->set_sampling(false); - _session.capture_state_changed(SigSession::Stopped); + _session->capture_state_changed(SigSession::Stopped); session_save(); _view->hide_calibration(); - if (_session.get_device()->dev_inst()->mode != DSO && - strncmp(_session.get_device()->name().toUtf8(), "virtual", 7)) { - const boost::shared_ptr logic_snapshot(_session.get_snapshot(SR_CHANNEL_LOGIC)); + if (_session->get_device()->dev_inst()->mode != DSO && + strncmp(_session->get_device()->name().toUtf8(), "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)); + const boost::shared_ptr analog_snapshot(_session->get_snapshot(SR_CHANNEL_ANALOG)); assert(analog_snapshot); if (!logic_snapshot->empty() || !analog_snapshot->empty()) { @@ -550,15 +566,18 @@ void MainWindow::device_detach() } _hot_detach = true; - if (!_session.get_saving()) + if (!_session->get_saving()) device_detach_post(); } void MainWindow::device_detach_post() { + SigSession *_session = _control->GetSession(); + if (!_hot_detach) return; + DeviceManager &_device_manager = _control->GetDeviceManager(); _hot_detach = false; struct sr_dev_driver **const drivers = sr_driver_list(); struct sr_dev_driver **driver; @@ -566,16 +585,18 @@ void MainWindow::device_detach_post() if (*driver) _device_manager.driver_scan(*driver); - _session.set_default_device(boost::bind(&MainWindow::session_error, this, + _session->set_default_device(boost::bind(&MainWindow::session_error, this, QString(tr("Set Default Device failed")), _1)); update_device_list(); } void MainWindow::device_changed(bool close) { + SigSession *_session = _control->GetSession(); + if (close) { _sampling_bar->set_sampling(false); - _session.set_default_device(boost::bind(&MainWindow::session_error, this, + _session->set_default_device(boost::bind(&MainWindow::session_error, this, QString(tr("Set Default Device failed")), _1)); } update_device_list(); @@ -583,36 +604,40 @@ void MainWindow::device_changed(bool close) void MainWindow::on_run_stop() { - switch(_session.get_capture_state()) { + SigSession *_session = _control->GetSession(); + + switch(_session->get_capture_state()) { case SigSession::Init: case SigSession::Stopped: commit_trigger(false); - _session.start_capture(false, + _session->start_capture(false, boost::bind(&MainWindow::session_error, this, QString(tr("Capture failed")), _1)); _view->capture_init(); break; case SigSession::Running: - _session.stop_capture(); + _session->stop_capture(); break; } } void MainWindow::on_instant_stop() { - switch(_session.get_capture_state()) { + SigSession *_session = _control->GetSession(); + + switch(_session->get_capture_state()) { case SigSession::Init: case SigSession::Stopped: commit_trigger(true); - _session.start_capture(true, + _session->start_capture(true, boost::bind(&MainWindow::session_error, this, QString(tr("Capture failed")), _1)); _view->capture_init(); break; case SigSession::Running: - _session.stop_capture(); + _session->stop_capture(); break; } } @@ -631,26 +656,28 @@ void MainWindow::on_show_error() QString ch_status = ""; uint64_t error_pattern; - switch(_session.get_error()) { + SigSession *_session = _control->GetSession(); + + switch(_session->get_error()) { case SigSession::Hw_err: - _session.set_repeating(false); - _session.stop_capture(); + _session->set_repeating(false); + _session->stop_capture(); title = tr("Hardware Operation Failed"); details = tr("Please replug device to refresh hardware configuration!"); break; case SigSession::Malloc_err: - _session.set_repeating(false); - _session.stop_capture(); + _session->set_repeating(false); + _session->stop_capture(); title = tr("Malloc Error"); details = tr("Memory is not enough for this sample!\nPlease reduce the sample depth!"); break; case SigSession::Test_data_err: - _session.set_repeating(false); - _session.stop_capture(); + _session->set_repeating(false); + _session->stop_capture(); _sampling_bar->set_sampling(false); - _session.capture_state_changed(SigSession::Stopped); + _session->capture_state_changed(SigSession::Stopped); title = tr("Data Error"); - error_pattern = _session.get_error_pattern(); + error_pattern = _session->get_error_pattern(); for(int i = 0; i < 16; i++) { if (error_pattern & 0x01) ch_status += "X "; @@ -665,11 +692,11 @@ void MainWindow::on_show_error() case SigSession::Pkt_data_err: title = tr("Packet Error"); details = tr("the content of received packet are not expected!"); - _session.refresh(0); + _session->refresh(0); break; case SigSession::Data_overflow: - _session.set_repeating(false); - _session.stop_capture(); + _session->set_repeating(false); + _session->stop_capture(); title = tr("Data Overflow"); details = tr("USB bandwidth can not support current sample rate! \nPlease reduce the sample rate!"); break; @@ -680,7 +707,7 @@ void MainWindow::on_show_error() } dialogs::DSMessageBox msg(this); - connect(_session.get_device().get(), SIGNAL(device_updated()), &msg, SLOT(accept())); + connect(_session->get_device(), SIGNAL(device_updated()), &msg, SLOT(accept())); QFont font("Monaco"); font.setStyleHint(QFont::Monospace); font.setFixedPitch(true); @@ -692,18 +719,20 @@ void MainWindow::on_show_error() msg.mBox()->setIcon(QMessageBox::Warning); msg.exec(); - _session.clear_error(); + _session->clear_error(); } void MainWindow::capture_state_changed(int state) { - if (!_session.repeat_check()) { + SigSession *_session = _control->GetSession(); + + if (!_session->repeat_check()) { _file_bar->enable_toggle(state != SigSession::Running); _sampling_bar->set_sampling(state == SigSession::Running); _view->on_state_changed(state != SigSession::Running); - if (_session.get_device()->dev_inst()->mode != DSO || - _session.get_instant()) { + if (_session->get_device()->dev_inst()->mode != DSO || + _session->get_instant()) { _sampling_bar->enable_toggle(state != SigSession::Running); _trig_bar->enable_toggle(state != SigSession::Running); //_measure_dock->widget()->setEnabled(state != SigSession::Running); @@ -727,11 +756,12 @@ void MainWindow::session_save() #endif AppConfig &app = AppConfig::Instance(); + SigSession *_session = _control->GetSession(); if(dir.mkpath(path)) { dir.cd(path); - QString driver_name = _session.get_device()->name(); - QString mode_name = QString::number(_session.get_device()->dev_inst()->mode); + QString driver_name = _session->get_device()->name(); + QString mode_name = QString::number(_session->get_device()->dev_inst()->mode); QString lang_name = ".ses" + QString::number(app._frameOptions.language); QString file_name = dir.absolutePath() + "/" + driver_name + mode_name + @@ -762,7 +792,9 @@ void MainWindow::on_protocol(bool visible) void MainWindow::on_trigger(bool visible) { - if (_session.get_device()->dev_inst()->mode != DSO) { + SigSession *_session = _control->GetSession(); + + if (_session->get_device()->dev_inst()->mode != DSO) { _trigger_widget->init(); _trigger_dock->setVisible(visible); _dso_trigger_dock->setVisible(false); @@ -779,16 +811,17 @@ void MainWindow::commit_trigger(bool instant) int i = 0; AppConfig &app = AppConfig::Instance(); + SigSession *_session = _control->GetSession(); ds_trigger_init(); - if (_session.get_device()->dev_inst()->mode != LOGIC || + if (_session->get_device()->dev_inst()->mode != LOGIC || instant) return; if (!_trigger_widget->commit_trigger()) { /* simple trigger check trigger_enable */ - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { assert(s); boost::shared_ptr logicSig; @@ -810,7 +843,7 @@ void MainWindow::commit_trigger(bool instant) msg.exec(); if (msg.mBox()->clickedButton() == cancelButton) { - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { assert(s); boost::shared_ptr logicSig; @@ -876,7 +909,9 @@ void MainWindow::on_save() // dialogs::RegionOptions *regionDlg = new dialogs::RegionOptions(_view, _session, this); // regionDlg->exec(); - _session.set_saving(true); + SigSession *_session = _control->GetSession(); + + _session->set_saving(true); QString session_file; QDir dir; #if QT_VERSION >= 0x050400 @@ -899,6 +934,7 @@ void MainWindow::on_save() void MainWindow::on_export() { using pv::dialogs::StoreProgress; + SigSession *_session = _control->GetSession(); StoreProgress *dlg = new StoreProgress(_session, this); dlg->export_run(); @@ -927,36 +963,21 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev) sessionObj["Version"].toInt() != Session_Version) return false; + SigSession *_session = _control->GetSession(); + // check device and mode - const sr_dev_inst *const sdi = _session.get_device()->dev_inst(); + const sr_dev_inst *const sdi = _session->get_device()->dev_inst(); if ((!file_dev && strcmp(sdi->driver->name, sessionObj["Device"].toString().toUtf8()) != 0) || sdi->mode != sessionObj["DeviceMode"].toDouble()) { MsgBox::Show(NULL, "Session File is not compatible with current device or mode!", this); return false; } - - AppConfig &app = AppConfig::Instance(); - - // check language - if (sessionObj.contains("Language")) { - switchLanguage(sessionObj["Language"].toInt()); - } else if (sessionObj.contains("Operation Mode")) { - bool language_matched = _session.get_device()->set_config(NULL, NULL, SR_CONF_OPERATION_MODE, - g_variant_new_string(sessionObj["Operation Mode"].toString().toUtf8())); - if (!language_matched) { - if (app._frameOptions.language != QLocale::Chinese) - switchLanguage(QLocale::Chinese); - else - switchLanguage(QLocale::English); - } - } - + // clear decoders if (sdi->mode == LOGIC) { _protocol_widget->del_all_protocol(); - } - + } // load device settings GVariant *gvar_opts; @@ -970,21 +991,21 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev) if (!sessionObj.contains(info->name)) continue; if (info->datatype == SR_T_BOOL) - _session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_boolean(sessionObj[info->name].toDouble())); + _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_boolean(sessionObj[info->name].toDouble())); else if (info->datatype == SR_T_UINT64) - _session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_uint64(sessionObj[info->name].toString().toULongLong())); + _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_uint64(sessionObj[info->name].toString().toULongLong())); else if (info->datatype == SR_T_UINT8) - _session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_byte(sessionObj[info->name].toString().toUInt())); + _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_byte(sessionObj[info->name].toString().toUInt())); else if (info->datatype == SR_T_FLOAT) - _session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_double(sessionObj[info->name].toDouble())); + _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_double(sessionObj[info->name].toDouble())); else if (info->datatype == SR_T_CHAR) - _session.get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toUtf8())); + _session->get_device()->set_config(NULL, NULL, info->key, g_variant_new_string(sessionObj[info->name].toString().toUtf8())); } } // load channel settings if (file_dev && (sdi->mode == DSO)) { - for (const GSList *l = _session.get_device()->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _session->get_device()->dev_inst()->channels; l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); foreach (const QJsonValue &value, sessionObj["channel"].toArray()) { @@ -1003,7 +1024,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev) } } } else { - for (const GSList *l = _session.get_device()->dev_inst()->channels; l; l = l->next) { + for (const GSList *l = _session->get_device()->dev_inst()->channels; l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; assert(probe); bool isEnabled = false; @@ -1029,12 +1050,12 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev) } } - //_session.init_signals(); - _session.reload(); + //_session->init_signals(); + _session->reload(); // load signal setting if (file_dev && (sdi->mode == DSO)) { - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { foreach (const QJsonValue &value, sessionObj["channel"].toArray()) { QJsonObject obj = value.toObject(); if ((strcmp(s->get_name().toStdString().c_str(), g_strdup(obj["name"].toString().toStdString().c_str())) == 0) && @@ -1053,7 +1074,7 @@ bool MainWindow::load_session_json(QJsonDocument json, bool file_dev) } } } else { - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { foreach (const QJsonValue &value, sessionObj["channel"].toArray()) { QJsonObject obj = value.toObject(); if ((s->get_index() == obj["index"].toDouble()) && @@ -1126,11 +1147,12 @@ bool MainWindow::on_store_session(QString name) //outStream.setGenerateByteOrderMark(true); // UTF-8 without BOM AppConfig &app = AppConfig::Instance(); + SigSession *_session = _control->GetSession(); GVariant *gvar_opts; GVariant *gvar; gsize num_opts; - const sr_dev_inst *const sdi = _session.get_device()->dev_inst(); + const sr_dev_inst *const sdi = _session->get_device()->dev_inst(); QJsonObject sessionVar; QJsonArray channelVar; sessionVar["Version"]= QJsonValue::fromVariant(Session_Version); @@ -1145,7 +1167,7 @@ bool MainWindow::on_store_session(QString name) for (unsigned int i = 0; i < num_opts; i++) { const struct sr_config_info *const info = sr_config_info_get(options[i]); - gvar = _session.get_device()->get_config(NULL, NULL, info->key); + gvar = _session->get_device()->get_config(NULL, NULL, info->key); if (gvar != NULL) { if (info->datatype == SR_T_BOOL) sessionVar[info->name] = QJsonValue::fromVariant(g_variant_get_boolean(gvar)); @@ -1161,7 +1183,7 @@ bool MainWindow::on_store_session(QString name) } } - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { QJsonObject s_obj; s_obj["index"] = s->get_index(); s_obj["type"] = s->get_type(); @@ -1200,7 +1222,7 @@ bool MainWindow::on_store_session(QString name) } sessionVar["channel"] = channelVar; - if (_session.get_device()->dev_inst()->mode == LOGIC) { + if (_session->get_device()->dev_inst()->mode == LOGIC) { sessionVar["trigger"] = _trigger_widget->get_session(); } @@ -1209,7 +1231,7 @@ bool MainWindow::on_store_session(QString name) sessionVar["decoder"] = ss.json_decoders(); - if (_session.get_device()->dev_inst()->mode == DSO) { + if (_session->get_device()->dev_inst()->mode == DSO) { sessionVar["measure"] = _view->get_viewstatus()->get_session(); } @@ -1236,14 +1258,16 @@ void MainWindow::restore_dock() } } - if (_session.get_device()->dev_inst()->mode != DSO) { + SigSession *_session = _control->GetSession(); + + if (_session->get_device()->dev_inst()->mode != DSO) { _dso_trigger_dock->setVisible(false); _trig_bar->update_trig_btn(_trigger_dock->isVisible()); } else { _trigger_dock->setVisible(false); _trig_bar->update_trig_btn(_dso_trigger_dock->isVisible()); } - if (_session.get_device()->dev_inst()->mode != LOGIC) { + if (_session->get_device()->dev_inst()->mode != LOGIC) { on_protocol(false); @@ -1258,7 +1282,8 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) (void) object; if ( event->type() == QEvent::KeyPress ) { - const vector< boost::shared_ptr > sigs(_session.get_signals()); + SigSession *_session = _control->GetSession(); + const vector< boost::shared_ptr > sigs(_session->get_signals()); QKeyEvent *ke = (QKeyEvent *) event; switch(ke->key()) { case Qt::Key_S: @@ -1268,7 +1293,7 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) on_instant_stop(); break; case Qt::Key_T: - if (_session.get_device()->dev_inst()->mode == DSO) + if (_session->get_device()->dev_inst()->mode == DSO) on_trigger(!_dso_trigger_dock->isVisible()); else on_trigger(!_trigger_dock->isVisible()); @@ -1367,7 +1392,8 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) void MainWindow::switchLanguage(int language) { - boost::shared_ptr dev = _session.get_device(); + SigSession *_session = _control->GetSession(); + DevInst *dev = _session->get_device(); dev->set_config(NULL, NULL, SR_CONF_LANGUAGE, g_variant_new_int16(language)); AppConfig &app = AppConfig::Instance(); @@ -1408,7 +1434,9 @@ void MainWindow::switchTheme(QString style) qss.open(QFile::ReadOnly | QFile::Text); qApp->setStyleSheet(qss.readAll()); qss.close(); - _session.data_updated(); + + SigSession *_session = _control->GetSession(); + _session->data_updated(); } void MainWindow::on_open_doc(){ diff --git a/DSView/pv/mainwindow.h b/DSView/pv/mainwindow.h index 0571aeba..7dee5f3a 100755 --- a/DSView/pv/mainwindow.h +++ b/DSView/pv/mainwindow.h @@ -27,8 +27,8 @@ #include #include - -#include "sigsession.h" +#include + #include "dialogs/dsmessagebox.h" class QAction; @@ -40,9 +40,10 @@ class QToolBar; class QWidget; class QDockWidget; -namespace pv { +class AppControl; -class DeviceManager; +namespace pv { + namespace toolbars { class SamplingBar; @@ -63,6 +64,12 @@ namespace view { class View; } +namespace device{ + class DevInst; +} + +using namespace pv::device; + //The mainwindow,referenced by MainFrame //TODO: create graph view,toolbar,and show device list class MainWindow : public QMainWindow @@ -73,9 +80,7 @@ private: static constexpr int Session_Version = 2; public: - explicit MainWindow(DeviceManager &device_manager, - const char *open_file_name = NULL, - QWidget *parent = 0); + explicit MainWindow(QWidget *parent = 0); protected: void closeEvent(QCloseEvent *event); @@ -170,10 +175,8 @@ signals: void prgRate(int progress); private: - DeviceManager &_device_manager; - - SigSession _session; - bool _hot_detach; + AppControl *_control; + bool _hot_detach; pv::view::View *_view; dialogs::DSMessageBox *_msg; diff --git a/DSView/pv/sigsession.cpp b/DSView/pv/sigsession.cpp index 7ceed522..0774aca0 100755 --- a/DSView/pv/sigsession.cpp +++ b/DSView/pv/sigsession.cpp @@ -89,8 +89,7 @@ namespace pv { // TODO: This should not be necessary SigSession* SigSession::_session = NULL; -SigSession::SigSession(DeviceManager &device_manager) : - _device_manager(device_manager), +SigSession::SigSession(DeviceManager *device_manager) : _capture_state(Init), _instant(false), _error(No_err), @@ -100,12 +99,19 @@ SigSession::SigSession(DeviceManager &device_manager) : _repeat_hold_prg(0), _map_zoom(0) { - // TODO: This should not be necessary - _session = this; + void *p = this; + _appCntrol = NULL; + + _hotplug_handle = 0; + _dev_inst = NULL; + _device_manager = device_manager; + // TODO: This should not be necessary + _session = this; _hot_attach = false; _hot_detach = false; _group_cnt = 0; - register_hotplug_callback(); + + _feed_timer.stop(); _noData_cnt = 0; _data_lock = false; @@ -135,38 +141,39 @@ SigSession::SigSession(DeviceManager &device_manager) : connect(&_feed_timer, SIGNAL(timeout()), this, SLOT(feed_timeout())); } +//SigSession::SigSession(SigSession &o){(void)o;} + SigSession::~SigSession() { - stop_capture(); - - ds_trigger_destroy(); - - _dev_inst->release(); - - // TODO: This should not be necessary - _session = NULL; - - if (_hotplug_handle) { - stop_hotplug_proc(); - deregister_hotplug_callback(); - } + Close(); } -boost::shared_ptr SigSession::get_device() const +DevInst* SigSession::get_device() const { return _dev_inst; } +void SigSession::deselect_device() +{ + _decode_traces.clear(); + _group_traces.clear(); + _dev_inst = NULL; +} + /* when be called, it will call 4DSL lib sr_session_new, and create a session struct in the lib */ -void SigSession::set_device(boost::shared_ptr dev_inst) +void SigSession::set_device(DevInst *dev_inst) { - using pv::device::Device; - // Ensure we are not capturing before setting the device //stop_capture(); + assert(dev_inst); + + if (_dev_inst){ + _dev_inst->dev_inst(); + } + if (_dev_inst) { sr_session_datafeed_callback_remove_all(); _dev_inst->release(); @@ -202,29 +209,27 @@ void SigSession::set_file(QString name) { // Deslect the old device, because file type detection in File::create // destorys the old session inside libsigrok. + deselect_device(); + try { - set_device(boost::shared_ptr()); - } catch(const QString e) { - throw(e); - return; - } - try { - set_device(boost::shared_ptr(device::File::create(name))); + set_device(device::File::create(name)); } catch(const QString e) { throw(e); return; } } -void SigSession::close_file(boost::shared_ptr dev_inst) +void SigSession::close_file(DevInst *dev_inst) { assert(dev_inst); + assert(_device_manager); + try { dev_inst->device_updated(); set_repeating(false); stop_capture(); capture_state_changed(SigSession::Stopped); - _device_manager.del_device(dev_inst); + _device_manager->del_device(dev_inst); } catch(const QString e) { throw(e); return; @@ -233,22 +238,25 @@ void SigSession::close_file(boost::shared_ptr dev_inst) void SigSession::set_default_device(boost::function error_handler) { - boost::shared_ptr default_device; - const list > &devices = - _device_manager.devices(); + assert(_device_manager); + DevInst *default_device = NULL; + + const list &devices = _device_manager->devices(); if (!devices.empty()) { // Fall back to the first device in the list. default_device = devices.front(); // Try and find the DreamSourceLab device and select that by default - BOOST_FOREACH (boost::shared_ptr dev, devices) - if (dev->dev_inst() && - !dev->name().contains("virtual")) { + for (DevInst *dev : devices) + if (dev->dev_inst() && !dev->name().contains("virtual")) { default_device = dev; break; } - try { + } + + if (default_device != NULL){ + try { set_device(default_device); } catch(const QString e) { error_handler(e); @@ -257,20 +265,22 @@ void SigSession::set_default_device(boost::function error_ } } -void SigSession::release_device(device::DevInst *dev_inst) +void SigSession::release_device(DevInst *dev_inst) { - (void)dev_inst; - assert(_dev_inst.get() == dev_inst); + if (_dev_inst == NULL) + return; + assert(dev_inst); + assert(_dev_inst == dev_inst); assert(get_capture_state() != Running); - _dev_inst = boost::shared_ptr(); - //_dev_inst.reset(); + + _dev_inst = NULL; } SigSession::capture_state SigSession::get_capture_state() const { boost::lock_guard lock(_sampling_mutex); - return _capture_state; + return _capture_state; } uint64_t SigSession::cur_samplelimits() const @@ -447,7 +457,7 @@ void SigSession::start_capture(bool instant, } // stop previous capture - stop_capture(); + stop_capture(); // reset measure of dso signal BOOST_FOREACH(const boost::shared_ptr s, _signals) { @@ -464,24 +474,24 @@ void SigSession::start_capture(bool instant, _instant = true; capture_init(); - // Check that at least one probe is enabled - const GSList *l; + // Check that at least one probe is enabled + const GSList *l; for (l = _dev_inst->dev_inst()->channels; l; l = l->next) { sr_channel *const probe = (sr_channel*)l->data; - assert(probe); - if (probe->enabled) - break; - } - if (!l) { - error_handler(tr("No probes enabled.")); + assert(probe); + if (probe->enabled) + break; + } + if (!l) { + error_handler(tr("No probes enabled.")); data_updated(); set_repeating(false); capture_state_changed(SigSession::Stopped); - return; - } + return; + } - // Begin the session - _sampling_thread.reset(new boost::thread( + // Begin the session + _sampling_thread.reset(new boost::thread( &SigSession::sample_thread_proc, this, _dev_inst, error_handler)); } @@ -497,11 +507,11 @@ void SigSession::stop_capture() (*i)->decoder()->stop_decode(); if (get_capture_state() != Running) - return; + return; - sr_session_stop(); + sr_session_stop(); - // Check that sampling stopped + // Check that sampling stopped if (_sampling_thread.get()) _sampling_thread->join(); _sampling_thread.reset(); @@ -530,10 +540,10 @@ bool SigSession::get_capture_status(bool &triggered, int &progress) return false; } -vector< boost::shared_ptr > SigSession::get_signals() +vector< boost::shared_ptr >& SigSession::get_signals() { //boost::lock_guard lock(_signals_mutex); - return _signals; + return _signals; } vector< boost::shared_ptr > SigSession::get_group_signals() @@ -562,12 +572,12 @@ bool SigSession::get_instant() void SigSession::set_capture_state(capture_state state) { boost::lock_guard lock(_sampling_mutex); - _capture_state = state; + _capture_state = state; data_updated(); - capture_state_changed(state); + capture_state_changed(state); } -void SigSession::sample_thread_proc(boost::shared_ptr dev_inst, +void SigSession::sample_thread_proc(DevInst *dev_inst, boost::function error_handler) { assert(dev_inst); @@ -934,20 +944,20 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) void SigSession::feed_in_meta(const sr_dev_inst *sdi, const sr_datafeed_meta &meta) { - (void)sdi; + (void)sdi; - for (const GSList *l = meta.config; l; l = l->next) { + for (const GSList *l = meta.config; l; l = l->next) { const sr_config *const src = (const sr_config*)l->data; - switch (src->key) { - case SR_CONF_SAMPLERATE: - /// @todo handle samplerate changes - /// samplerate = (uint64_t *)src->value; - break; - default: - // Unknown metadata is not an error. - break; - } - } + switch (src->key) { + case SR_CONF_SAMPLERATE: + /// @todo handle samplerate changes + /// samplerate = (uint64_t *)src->value; + break; + default: + // Unknown metadata is not an error. + break; + } + } } void SigSession::feed_in_trigger(const ds_trigger_pos &trigger_pos) @@ -980,9 +990,9 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) { //boost::lock_guard lock(_data_mutex); if (!_logic_data || _cur_logic_snapshot->memory_failed()) { - qDebug() << "Unexpected logic packet"; - return; - } + qDebug() << "Unexpected logic packet"; + return; + } if (logic.data_error == 1) { _error = Test_data_err; @@ -998,7 +1008,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic) // this after both analog and logic sweeps have begun. frame_began(); } else { - // Append to the existing data snapshot + // Append to the existing data snapshot _cur_logic_snapshot->append_payload(logic); } @@ -1098,13 +1108,13 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) //boost::lock_guard lock(_data_mutex); if(!_analog_data || _cur_analog_snapshot->memory_failed()) - { - qDebug() << "Unexpected analog packet"; - return; // This analog packet was not expected. - } + { + qDebug() << "Unexpected analog packet"; + return; // This analog packet was not expected. + } if (_cur_analog_snapshot->last_ended()) - { + { // reset scale of analog signal BOOST_FOREACH(const boost::shared_ptr s, _signals) { @@ -1118,8 +1128,8 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) // first payload _cur_analog_snapshot->first_payload(analog, _dev_inst->get_sample_limit(), _dev_inst->dev_inst()->channels); } else { - // Append to the existing data snapshot - _cur_analog_snapshot->append_payload(analog); + // Append to the existing data snapshot + _cur_analog_snapshot->append_payload(analog); } if (_cur_analog_snapshot->memory_failed()) { @@ -1136,14 +1146,14 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog) void SigSession::data_feed_in(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *packet) { - assert(sdi); - assert(packet); + assert(sdi); + assert(packet); boost::lock_guard lock(_data_mutex); if (_data_lock && packet->type != SR_DF_END) return; - + if (packet->type != SR_DF_END && packet->status != SR_PKT_OK) { _error = Pkt_data_err; @@ -1151,36 +1161,36 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, return; } - switch (packet->type) { - case SR_DF_HEADER: - feed_in_header(sdi); - break; + switch (packet->type) { + case SR_DF_HEADER: + feed_in_header(sdi); + break; - case SR_DF_META: - assert(packet->payload); - feed_in_meta(sdi, + case SR_DF_META: + assert(packet->payload); + feed_in_meta(sdi, *(const sr_datafeed_meta*)packet->payload); - break; + break; case SR_DF_TRIGGER: assert(packet->payload); feed_in_trigger(*(const ds_trigger_pos*)packet->payload); break; - case SR_DF_LOGIC: - assert(packet->payload); + case SR_DF_LOGIC: + assert(packet->payload); feed_in_logic(*(const sr_datafeed_logic*)packet->payload); - break; + break; case SR_DF_DSO: assert(packet->payload); feed_in_dso(*(const sr_datafeed_dso*)packet->payload); break; - case SR_DF_ANALOG: - assert(packet->payload); + case SR_DF_ANALOG: + assert(packet->payload); feed_in_analog(*(const sr_datafeed_analog*)packet->payload); - break; + break; case SR_DF_OVERFLOW: { @@ -1190,9 +1200,9 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, } break; } - case SR_DF_END: - { - { + case SR_DF_END: + { + { //boost::lock_guard lock(_data_mutex); if (!_cur_logic_snapshot->empty()) { BOOST_FOREACH(const boost::shared_ptr g, _group_traces) @@ -1212,7 +1222,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, BOOST_FOREACH(const boost::shared_ptr d, _decode_traces) d->frame_ended(); - } + } if (packet->status != SR_PKT_OK) { _error = Pkt_data_err; @@ -1221,23 +1231,23 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, frame_ended(); if (get_device()->dev_inst()->mode != LOGIC) set_session_time(QDateTime::currentDateTime()); - break; - } - } + break; + } + } } void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *packet, void *cb_data) { - (void) cb_data; - assert(_session); - _session->data_feed_in(sdi, packet); + (void) cb_data; + assert(_session); + _session->data_feed_in(sdi, packet); } /* * hotplug function */ -int SigSession::hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev, +int SigSession::hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev, libusb_hotplug_event event, void *user_data) { (void)ctx; @@ -1293,12 +1303,12 @@ void SigSession::register_hotplug_callback() int ret; ret = libusb_hotplug_register_callback(NULL, (libusb_hotplug_event)(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | - LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), + LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT), (libusb_hotplug_flag)LIBUSB_HOTPLUG_ENUMERATE, 0x2A0E, LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY, hotplug_callback, NULL, &_hotplug_handle); if (LIBUSB_SUCCESS != ret){ - qDebug() << "Error creating a hotplug callback\n"; + qDebug() << "Error creating a hotplug callback\n"; } } @@ -1369,7 +1379,7 @@ uint16_t SigSession::get_ch_num(int type) bool SigSession::add_decoder(srd_decoder *const dec, bool silent, DecoderStatus *dstatus) -{ +{ bool ret = false; map probes; boost::shared_ptr decoder_stack; @@ -1379,7 +1389,7 @@ bool SigSession::add_decoder(srd_decoder *const dec, bool silent, DecoderStatus // Create the decoder decoder_stack = boost::shared_ptr( - new data::DecoderStack(*this, dec, dstatus)); + new data::DecoderStack(this, dec, dstatus)); // Make a list of all the probes std::vector all_probes; @@ -1395,7 +1405,7 @@ bool SigSession::add_decoder(srd_decoder *const dec, bool silent, DecoderStatus // Create the decode signal boost::shared_ptr d( - new view::DecodeTrace(*this, decoder_stack, + new view::DecodeTrace(this, decoder_stack, _decode_traces.size())); // set view early for decode start/end region setting BOOST_FOREACH(const boost::shared_ptr s, _signals) { @@ -1524,9 +1534,9 @@ void SigSession::spectrum_rebuild() // if not, rebuild if (iter == _spectrum_traces.end()) { boost::shared_ptr spectrum_stack( - new data::SpectrumStack(*this, dsoSig->get_index())); + new data::SpectrumStack(this, dsoSig->get_index())); boost::shared_ptr spectrum_trace( - new view::SpectrumTrace(*this, spectrum_stack, dsoSig->get_index())); + new view::SpectrumTrace(this, spectrum_stack, dsoSig->get_index())); _spectrum_traces.push_back(spectrum_trace); } } @@ -1569,7 +1579,7 @@ void SigSession::math_rebuild(bool enable, { boost::lock_guard lock(_data_mutex); boost::shared_ptr math_stack( - new data::MathStack(*this, dsoSig1, dsoSig2, type)); + new data::MathStack(this, dsoSig1, dsoSig2, type)); _math_trace.reset(new view::MathTrace(enable, math_stack, dsoSig1, dsoSig2)); if (_math_trace && _math_trace->enabled()) { _math_trace->get_math_stack()->set_samplerate(_dev_inst->get_sample_rate()); @@ -1815,4 +1825,44 @@ void SigSession::set_stop_scale(float scale) _stop_scale = scale; } + sr_dev_inst* SigSession::get_dev_inst_c() + { + void *p = this; + void *p2 = this->_appCntrol; + if (_dev_inst != NULL){ + return _dev_inst->dev_inst(); + } + return NULL; + } + + void SigSession::Open() + { + register_hotplug_callback(); + } + + void SigSession::Close() + { + if (_session == NULL) + return; + + stop_capture(); + + ds_trigger_destroy(); + + if (_dev_inst) + { + _dev_inst->release(); + } + + // TODO: This should not be necessary + _session = NULL; + + if (_hotplug_handle) + { + stop_hotplug_proc(); + deregister_hotplug_callback(); + _hotplug_handle = NULL; + } + } + } // namespace pv diff --git a/DSView/pv/sigsession.h b/DSView/pv/sigsession.h index 6d66c0b5..3e2b8fb3 100755 --- a/DSView/pv/sigsession.h +++ b/DSView/pv/sigsession.h @@ -94,6 +94,8 @@ class Decoder; class DecoderFactory; } +using namespace pv::device; + //created by MainWindow class SigSession : public QObject { @@ -130,25 +132,30 @@ public: Data_overflow }; +private: + // SigSession(SigSession &o); + public: - SigSession(DeviceManager &device_manager); + explicit SigSession(DeviceManager *device_manager); - ~SigSession(); + ~SigSession(); - boost::shared_ptr get_device() const; + DevInst* get_device() const; /** * Sets device instance that will be used in the next capture session. */ - void set_device(boost::shared_ptr dev_inst); + void set_device(DevInst *dev_inst); + + void deselect_device(); void set_file(QString name); - void close_file(boost::shared_ptr dev_inst); + void close_file(DevInst *dev_inst); void set_default_device(boost::function error_handler); - void release_device(device::DevInst *dev_inst); + void release_device(DevInst *dev_inst); capture_state get_capture_state() const; @@ -173,7 +180,7 @@ public: std::set< boost::shared_ptr > get_data() const; - std::vector< boost::shared_ptr > + std::vector< boost::shared_ptr >& get_signals(); std::vector< boost::shared_ptr > @@ -213,8 +220,7 @@ public: void start_hotplug_proc(boost::function error_handler); void stop_hotplug_proc(); - void register_hotplug_callback(); - void deregister_hotplug_callback(); + uint16_t get_ch_num(int type); @@ -264,9 +270,18 @@ public: void exit_capture(); + sr_dev_inst* get_dev_inst_c(); + + void Open(); + + void Close(); + private: void set_capture_state(capture_state state); + void register_hotplug_callback(); + void deregister_hotplug_callback(); + private: /** * Attempts to autodetect the format. Failing that @@ -283,7 +298,7 @@ private: boost::function error_handler, sr_input_format *format = NULL); - void sample_thread_proc(boost::shared_ptr dev_inst, + void sample_thread_proc(DevInst *dev_inst, boost::function error_handler); // data feed @@ -306,77 +321,7 @@ private: static int hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev, libusb_hotplug_event event, void *user_data); -private: - DeviceManager &_device_manager; - /** - * The device instance that will be used in the next capture session. - */ - boost::shared_ptr _dev_inst; - - mutable boost::mutex _sampling_mutex; - capture_state _capture_state; - bool _instant; - uint64_t _cur_snap_samplerate; - uint64_t _cur_samplelimits; - - //mutable boost::mutex _signals_mutex; - std::vector< boost::shared_ptr > _signals; - std::vector< boost::shared_ptr > _group_traces; - - std::vector< boost::shared_ptr > _decode_traces; - pv::data::DecoderModel *_decoder_model; - - std::vector< boost::shared_ptr > _spectrum_traces; - boost::shared_ptr _lissajous_trace; - boost::shared_ptr _math_trace; - - mutable boost::mutex _data_mutex; - boost::shared_ptr _logic_data; - boost::shared_ptr _cur_logic_snapshot; - boost::shared_ptr _dso_data; - boost::shared_ptr _cur_dso_snapshot; - boost::shared_ptr _analog_data; - boost::shared_ptr _cur_analog_snapshot; - boost::shared_ptr _group_data; - boost::shared_ptr _cur_group_snapshot; - int _group_cnt; - - std::unique_ptr _sampling_thread; - - libusb_hotplug_callback_handle _hotplug_handle; - std::unique_ptr _hotplug; - bool _hot_attach; - bool _hot_detach; - - QTimer _feed_timer; - int _noData_cnt; - bool _data_lock; - bool _data_updated; - int _data_auto_lock; - - QDateTime _session_time; - uint64_t _trigger_pos; - bool _trigger_flag; - uint8_t _trigger_ch; - bool _hw_replied; - - error_state _error; - uint64_t _error_pattern; - - run_mode _run_mode; - int _repeat_intvl; - bool _repeating; - int _repeat_hold_prg; - - int _map_zoom; - - uint64_t _save_start; - uint64_t _save_end; - bool _saving; - - bool _dso_feed; - float _stop_scale; signals: void capture_state_changed(int state); @@ -442,6 +387,81 @@ private slots: void feed_timeout(); void repeat_update(); +public: + void *_appCntrol; + +private: + DeviceManager *_device_manager; + + /** + * The device instance that will be used in the next capture session. + */ + DevInst *_dev_inst; + + mutable boost::mutex _sampling_mutex; + capture_state _capture_state; + bool _instant; + uint64_t _cur_snap_samplerate; + uint64_t _cur_samplelimits; + + //mutable boost::mutex _signals_mutex; + std::vector< boost::shared_ptr > _signals; + std::vector< boost::shared_ptr > _group_traces; + + std::vector< boost::shared_ptr > _decode_traces; + pv::data::DecoderModel *_decoder_model; + + std::vector< boost::shared_ptr > _spectrum_traces; + boost::shared_ptr _lissajous_trace; + boost::shared_ptr _math_trace; + + mutable boost::mutex _data_mutex; + boost::shared_ptr _logic_data; + boost::shared_ptr _cur_logic_snapshot; + boost::shared_ptr _dso_data; + boost::shared_ptr _cur_dso_snapshot; + boost::shared_ptr _analog_data; + boost::shared_ptr _cur_analog_snapshot; + boost::shared_ptr _group_data; + boost::shared_ptr _cur_group_snapshot; + int _group_cnt; + + std::unique_ptr _sampling_thread; + + libusb_hotplug_callback_handle _hotplug_handle; + std::unique_ptr _hotplug; + bool _hot_attach; + bool _hot_detach; + + QTimer _feed_timer; + int _noData_cnt; + bool _data_lock; + bool _data_updated; + int _data_auto_lock; + + QDateTime _session_time; + uint64_t _trigger_pos; + bool _trigger_flag; + uint8_t _trigger_ch; + bool _hw_replied; + + error_state _error; + uint64_t _error_pattern; + + run_mode _run_mode; + int _repeat_intvl; + bool _repeating; + int _repeat_hold_prg; + + int _map_zoom; + + uint64_t _save_start; + uint64_t _save_end; + bool _saving; + + bool _dso_feed; + float _stop_scale; + private: // TODO: This should not be necessary. Multiple concurrent // sessions should should be supported and it should be diff --git a/DSView/pv/storesession.cpp b/DSView/pv/storesession.cpp index 88fe59bc..aed18575 100755 --- a/DSView/pv/storesession.cpp +++ b/DSView/pv/storesession.cpp @@ -75,7 +75,7 @@ namespace pv { } } -StoreSession::StoreSession(SigSession &session) : +StoreSession::StoreSession(SigSession *session) : _session(session), _outModule(NULL), _units_stored(0), @@ -90,7 +90,7 @@ StoreSession::~StoreSession() wait(); } -SigSession& StoreSession::session() +SigSession* StoreSession::session() { return _session; } @@ -125,7 +125,7 @@ QList StoreSession::getSuportedExportFormats(){ while(*supportedModules){ if(*supportedModules == NULL) break; - if (_session.get_device()->dev_inst()->mode != LOGIC && + if (_session->get_device()->dev_inst()->mode != LOGIC && strcmp((*supportedModules)->id, "csv")) break; QString format((*supportedModules)->desc); @@ -147,7 +147,7 @@ bool StoreSession::save_start() } std::set type_set; - BOOST_FOREACH(const boost::shared_ptr sig, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr sig, _session->get_signals()) { assert(sig); type_set.insert(sig->get_type()); } @@ -167,7 +167,7 @@ bool StoreSession::save_start() return false; } - const boost::shared_ptr snapshot(_session.get_snapshot(*type_set.begin())); + const boost::shared_ptr snapshot(_session->get_snapshot(*type_set.begin())); assert(snapshot); // Check we have data if (snapshot->empty()) { @@ -230,7 +230,7 @@ void StoreSession::save_proc(boost::shared_ptr snapshot) if ((logic_snapshot = boost::dynamic_pointer_cast(snapshot))) { uint16_t to_save_probes = 0; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { if (s->enabled() && logic_snapshot->has_data(s->get_index())) to_save_probes++; } @@ -238,7 +238,7 @@ void StoreSession::save_proc(boost::shared_ptr snapshot) num = logic_snapshot->get_block_num(); bool sample; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { int ch_type = s->get_type(); if (ch_type == SR_CHANNEL_LOGIC) { int ch_index = s->get_index(); @@ -283,7 +283,7 @@ void StoreSession::save_proc(boost::shared_ptr snapshot) } } else { int ch_type = -1; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { ch_type = s->get_type(); break; } @@ -383,7 +383,7 @@ QString StoreSession::meta_gen(boost::shared_ptr snapshot) return NULL; } - const sr_dev_inst *sdi = _session.get_device()->dev_inst(); + const sr_dev_inst *sdi = _session->get_device()->dev_inst(); meta = fopen(metafile.toUtf8().data(), "wb"); if (meta == NULL) { qDebug() << "Failed to create temp meta file."; @@ -421,68 +421,68 @@ QString StoreSession::meta_gen(boost::shared_ptr snapshot) fprintf(meta, "total blocks = %d\n", logic_snapshot->get_block_num()); } - s = sr_samplerate_string(_session.cur_snap_samplerate()); + s = sr_samplerate_string(_session->cur_snap_samplerate()); fprintf(meta, "samplerate = %s\n", s); if (sdi->mode == DSO) { - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_TIMEBASE); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_TIMEBASE); if (gvar != NULL) { uint64_t tmp_u64 = g_variant_get_uint64(gvar); fprintf(meta, "hDiv = %" PRIu64 "\n", tmp_u64); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MAX_TIMEBASE); if (gvar != NULL) { uint64_t tmp_u64 = g_variant_get_uint64(gvar); fprintf(meta, "hDiv max = %" PRIu64 "\n", tmp_u64); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MIN_TIMEBASE); if (gvar != NULL) { uint64_t tmp_u64 = g_variant_get_uint64(gvar); fprintf(meta, "hDiv min = %" PRIu64 "\n", tmp_u64); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS); if (gvar != NULL) { uint8_t tmp_u8 = g_variant_get_byte(gvar); fprintf(meta, "bits = %d\n", tmp_u8); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); if (gvar != NULL) { uint32_t tmp_u32 = g_variant_get_uint32(gvar); fprintf(meta, "ref min = %d\n", tmp_u32); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); if (gvar != NULL) { uint32_t tmp_u32 = g_variant_get_uint32(gvar); fprintf(meta, "ref max = %d\n", tmp_u32); g_variant_unref(gvar); } } else if (sdi->mode == LOGIC) { - fprintf(meta, "trigger time = %lld\n", _session.get_session_time().toMSecsSinceEpoch()); + fprintf(meta, "trigger time = %lld\n", _session->get_session_time().toMSecsSinceEpoch()); } else if (sdi->mode == ANALOG) { boost::shared_ptr analog_snapshot; if ((analog_snapshot = dynamic_pointer_cast(snapshot))) { uint8_t tmp_u8 = analog_snapshot->get_unit_bytes(); fprintf(meta, "bits = %d\n", tmp_u8*8); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); if (gvar != NULL) { uint32_t tmp_u32 = g_variant_get_uint32(gvar); fprintf(meta, "ref min = %d\n", tmp_u32); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); if (gvar != NULL) { uint32_t tmp_u32 = g_variant_get_uint32(gvar); fprintf(meta, "ref max = %d\n", tmp_u32); g_variant_unref(gvar); } } - fprintf(meta, "trigger pos = %" PRIu64 "\n", _session.get_trigger_pos()); + fprintf(meta, "trigger pos = %" PRIu64 "\n", _session->get_trigger_pos()); probecnt = 0; for (l = sdi->channels; l; l = l->next) { @@ -557,7 +557,7 @@ QString StoreSession::meta_gen(boost::shared_ptr snapshot) bool StoreSession::export_start() { std::set type_set; - BOOST_FOREACH(const boost::shared_ptr sig, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr sig, _session->get_signals()) { assert(sig); int _tp = sig->get_type(); type_set.insert(_tp); @@ -572,7 +572,7 @@ bool StoreSession::export_start() return false; } - const boost::shared_ptr snapshot(_session.get_snapshot(*type_set.begin())); + const boost::shared_ptr snapshot(_session->get_snapshot(*type_set.begin())); assert(snapshot); // Check we have data if (snapshot->empty()) { @@ -646,7 +646,7 @@ void StoreSession::export_proc(boost::shared_ptr snapshot) struct sr_output output; output.module = (sr_output_module*) _outModule; - output.sdi = _session.get_device()->dev_inst(); + output.sdi = _session->get_device()->dev_inst(); output.param = NULL; if(_outModule->init) _outModule->init(&output, params); @@ -664,7 +664,7 @@ void StoreSession::export_proc(boost::shared_ptr snapshot) struct sr_config *src; src = sr_config_new(SR_CONF_SAMPLERATE, - g_variant_new_uint64(_session.cur_snap_samplerate())); + g_variant_new_uint64(_session->cur_snap_samplerate())); meta.config = g_slist_append(NULL, src); src = sr_config_new(SR_CONF_LIMIT_SAMPLES, @@ -673,12 +673,12 @@ void StoreSession::export_proc(boost::shared_ptr snapshot) GVariant *gvar; uint8_t bits; - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_UNIT_BITS); if (gvar != NULL) { bits = g_variant_get_byte(gvar); g_variant_unref(gvar); } - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MIN); if (gvar != NULL) { src = sr_config_new(SR_CONF_REF_MIN, gvar); g_variant_unref(gvar); @@ -686,7 +686,7 @@ void StoreSession::export_proc(boost::shared_ptr snapshot) src = sr_config_new(SR_CONF_REF_MIN, g_variant_new_uint32(1)); } meta.config = g_slist_append(meta.config, src); - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_REF_MAX); if (gvar != NULL) { src = sr_config_new(SR_CONF_REF_MAX, gvar); g_variant_unref(gvar); @@ -721,7 +721,7 @@ void StoreSession::export_proc(boost::shared_ptr snapshot) uint64_t buf_sample_num = logic_snapshot->get_block_size(blk) * 8; buf_vec.clear(); buf_sample.clear(); - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { int ch_type = s->get_type(); if (ch_type == SR_CHANNEL_LOGIC) { int ch_index = s->get_index(); @@ -879,7 +879,7 @@ QString StoreSession::decoders_gen() QJsonArray StoreSession::json_decoders() { QJsonArray dec_array; - BOOST_FOREACH(boost::shared_ptr t, _session.get_decode_signals()) { + BOOST_FOREACH(boost::shared_ptr t, _session->get_decode_signals()) { QJsonObject dec_obj; QJsonArray stack_array; QJsonObject show_obj; @@ -959,18 +959,18 @@ QJsonArray StoreSession::json_decoders() void StoreSession::load_decoders(dock::ProtocolDock *widget, QJsonArray dec_array) { - if (_session.get_device()->dev_inst()->mode != LOGIC || + if (_session->get_device()->dev_inst()->mode != LOGIC || dec_array.empty()) return; foreach (const QJsonValue &dec_value, dec_array) { QJsonObject dec_obj = dec_value.toObject(); const vector< boost::shared_ptr > pre_dsigs( - _session.get_decode_signals()); + _session->get_decode_signals()); if (widget->sel_protocol(dec_obj["id"].toString())) widget->add_protocol(true); const vector< boost::shared_ptr > aft_dsigs( - _session.get_decode_signals()); + _session->get_decode_signals()); if (aft_dsigs.size() > pre_dsigs.size()) { const GSList *l; @@ -1130,24 +1130,24 @@ QString StoreSession::MakeSaveFile(bool bDlg) AppConfig &app = AppConfig::Instance(); if (app._userHistory.saveDir != "") { - default_name = app._userHistory.saveDir + "/" + _session.get_device()->name() + "-"; + default_name = app._userHistory.saveDir + "/" + _session->get_device()->name() + "-"; } else{ QDir _dir; QString _root = _dir.home().path(); - default_name = _root + "/" + _session.get_device()->name() + "-"; + default_name = _root + "/" + _session->get_device()->name() + "-"; } - for (const GSList *l = _session.get_device()->get_dev_mode_list(); + for (const GSList *l = _session->get_device()->get_dev_mode_list(); l; l = l->next) { const sr_dev_mode *mode = (const sr_dev_mode *)l->data; - if (_session.get_device()->dev_inst()->mode == mode->mode) { + if (_session->get_device()->dev_inst()->mode == mode->mode) { default_name += mode->acronym; break; } } - default_name += _session.get_session_time().toString("-yyMMdd-hhmmss"); + default_name += _session->get_session_time().toString("-yyMMdd-hhmmss"); // Show the dialog if (bDlg) @@ -1188,23 +1188,23 @@ QString StoreSession::MakeExportFile(bool bDlg) if (app._userHistory.exportDir != "") { - default_name = app._userHistory.exportDir + "/" + _session.get_device()->name() + "-"; + default_name = app._userHistory.exportDir + "/" + _session->get_device()->name() + "-"; } else{ QDir _dir; QString _root = _dir.home().path(); - default_name = _root + "/" + _session.get_device()->name() + "-"; + default_name = _root + "/" + _session->get_device()->name() + "-"; } - for (const GSList *l = _session.get_device()->get_dev_mode_list(); + for (const GSList *l = _session->get_device()->get_dev_mode_list(); l; l = l->next) { const sr_dev_mode *mode = (const sr_dev_mode *)l->data; - if (_session.get_device()->dev_inst()->mode == mode->mode) { + if (_session->get_device()->dev_inst()->mode == mode->mode) { default_name += mode->acronym; break; } } - default_name += _session.get_session_time().toString("-yyMMdd-hhmmss"); + default_name += _session->get_session_time().toString("-yyMMdd-hhmmss"); //ext name QList supportedFormats = getSuportedExportFormats(); @@ -1271,7 +1271,7 @@ QString StoreSession::MakeExportFile(bool bDlg) bool StoreSession::IsLogicDataType() { std::set type_set; - BOOST_FOREACH(const boost::shared_ptr sig, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr sig, _session->get_signals()) { assert(sig); type_set.insert(sig->get_type()); } diff --git a/DSView/pv/storesession.h b/DSView/pv/storesession.h index d7c201ca..45bd1e9a 100755 --- a/DSView/pv/storesession.h +++ b/DSView/pv/storesession.h @@ -53,11 +53,11 @@ private: const static int File_Version = 2; public: - StoreSession(SigSession &session); + StoreSession(SigSession *session); ~StoreSession(); - SigSession& session(); + SigSession* session(); std::pair progress() const; @@ -104,7 +104,7 @@ public: private: QString _file_name; QString _suffix; - SigSession &_session; + SigSession *_session; boost::thread _thread; diff --git a/DSView/pv/toolbars/filebar.cpp b/DSView/pv/toolbars/filebar.cpp index 4a3b8663..8db6d486 100755 --- a/DSView/pv/toolbars/filebar.cpp +++ b/DSView/pv/toolbars/filebar.cpp @@ -36,7 +36,7 @@ namespace pv { namespace toolbars { -FileBar::FileBar(SigSession &session, QWidget *parent) : +FileBar::FileBar(SigSession *session, QWidget *parent) : QToolBar("File Bar", parent), _enable(true), _session(session), @@ -205,10 +205,10 @@ void FileBar::on_actionDefault_triggered() return; } - QString driver_name = _session.get_device()->name(); - QString mode_name = QString::number(_session.get_device()->dev_inst()->mode); + QString driver_name = _session->get_device()->name(); + QString mode_name = QString::number(_session->get_device()->dev_inst()->mode); int language = QLocale::English; - GVariant *gvar_tmp = _session.get_device()->get_config(NULL, NULL, SR_CONF_LANGUAGE); + GVariant *gvar_tmp = _session->get_device()->get_config(NULL, NULL, SR_CONF_LANGUAGE); if (gvar_tmp != NULL) { language = g_variant_get_int16(gvar_tmp); g_variant_unref(gvar_tmp); diff --git a/DSView/pv/toolbars/filebar.h b/DSView/pv/toolbars/filebar.h index 261d5c31..32cbbe81 100755 --- a/DSView/pv/toolbars/filebar.h +++ b/DSView/pv/toolbars/filebar.h @@ -40,7 +40,7 @@ class FileBar : public QToolBar Q_OBJECT public: - explicit FileBar(SigSession &session, QWidget *parent = 0); + explicit FileBar(SigSession *session, QWidget *parent = 0); void enable_toggle(bool enable); @@ -73,7 +73,7 @@ private slots: private: bool _enable; - SigSession& _session; + SigSession* _session; QToolButton _file_button; diff --git a/DSView/pv/toolbars/logobar.cpp b/DSView/pv/toolbars/logobar.cpp index 85296798..6791226a 100755 --- a/DSView/pv/toolbars/logobar.cpp +++ b/DSView/pv/toolbars/logobar.cpp @@ -35,7 +35,7 @@ namespace pv { namespace toolbars { -LogoBar::LogoBar(SigSession &session, QWidget *parent) : +LogoBar::LogoBar(SigSession *session, QWidget *parent) : QToolBar("File Bar", parent), _enable(true), _connected(false), diff --git a/DSView/pv/toolbars/logobar.h b/DSView/pv/toolbars/logobar.h index 278def32..19cf5d3c 100755 --- a/DSView/pv/toolbars/logobar.h +++ b/DSView/pv/toolbars/logobar.h @@ -42,7 +42,7 @@ class LogoBar : public QToolBar Q_OBJECT public: - explicit LogoBar(SigSession &session, QWidget *parent = 0); + explicit LogoBar(SigSession *session, QWidget *parent = 0); void enable_toggle(bool enable); @@ -76,7 +76,7 @@ private slots: private: bool _enable; bool _connected; - SigSession& _session; + SigSession* _session; QToolButton _logo_button; diff --git a/DSView/pv/toolbars/samplingbar.cpp b/DSView/pv/toolbars/samplingbar.cpp index 46302c9c..2ecd10b0 100755 --- a/DSView/pv/toolbars/samplingbar.cpp +++ b/DSView/pv/toolbars/samplingbar.cpp @@ -46,13 +46,15 @@ using std::max; using std::min; using std::string; +using namespace pv::device; + namespace pv { namespace toolbars { const QString SamplingBar::RLEString = tr("(RLE)"); const QString SamplingBar::DIVString = tr(" / div"); -SamplingBar::SamplingBar(SigSession &session, QWidget *parent) : +SamplingBar::SamplingBar(SigSession *session, QWidget *parent) : QToolBar("Sampling Bar", parent), _session(session), _enable(true), @@ -140,7 +142,7 @@ void SamplingBar::changeEvent(QEvent *event) void SamplingBar::retranslateUi() { - boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (dev_inst && dev_inst->dev_inst()) { if (dev_inst->name().contains("virtual-demo")) _device_type.setText(tr("Demo")); @@ -163,17 +165,18 @@ void SamplingBar::retranslateUi() } _configure_button.setText(tr("Options")); _mode_button.setText(tr("Mode")); + + sr_dev_inst *dev_c = _session->get_dev_inst_c(); + if (_instant) { - if (_session.get_device() && - _session.get_device()->dev_inst()->mode == DSO) + if (dev_c && dev_c->mode == DSO) _instant_button.setText(_sampling ? tr("Stop") : tr("Single")); else _instant_button.setText(_sampling ? tr("Stop") : tr("Instant")); _run_stop_button.setText(tr("Start")); } else { _run_stop_button.setText(_sampling ? tr("Stop") : tr("Start")); - if (_session.get_device() && - _session.get_device()->dev_inst()->mode == DSO) + if (dev_c && dev_c->mode == DSO) _instant_button.setText(tr("Single")); else _instant_button.setText(tr("Instant")); @@ -185,7 +188,7 @@ void SamplingBar::retranslateUi() void SamplingBar::reStyle() { - boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (dev_inst && dev_inst->dev_inst()) { if (dev_inst->name().contains("virtual-demo")) _device_type.setIcon(QIcon(":/icons/demo.svg")); @@ -209,7 +212,7 @@ void SamplingBar::reStyle() if (true) { QString iconPath = GetIconPath(); _configure_button.setIcon(QIcon(iconPath+"/params.svg")); - _mode_button.setIcon(_session.get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : + _mode_button.setIcon(_session->get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : QIcon(iconPath+"/moder.svg")); _run_stop_button.setIcon(_sampling ? QIcon(iconPath+"/stop.svg") : QIcon(iconPath+"/start.svg")); @@ -219,9 +222,7 @@ void SamplingBar::reStyle() } } -void SamplingBar::set_device_list( - const std::list > &devices, - boost::shared_ptr selected) +void SamplingBar::set_device_list(const std::list &devices, DevInst *selected) { int selected_index = -1; @@ -232,7 +233,7 @@ void SamplingBar::set_device_list( _device_selector.clear(); _device_selector_map.clear(); - BOOST_FOREACH (boost::shared_ptr dev_inst, devices) { + for (DevInst *dev_inst : devices) { assert(dev_inst); const QString title = dev_inst->format_device_title(); const void *id = dev_inst->get_id(); @@ -258,22 +259,21 @@ void SamplingBar::set_device_list( _updating_device_selector = false; } -boost::shared_ptr SamplingBar::get_selected_device() const +DevInst* SamplingBar::get_selected_device() const { const int index = _device_selector.currentIndex(); if (index < 0) - return boost::shared_ptr(); + return NULL; const void *const id = _device_selector.itemData(index).value(); assert(id); - map >:: - const_iterator iter = _device_selector_map.find(id); - if (iter == _device_selector_map.end()) - return boost::shared_ptr(); + auto it = _device_selector_map.find(id); + if (it == _device_selector_map.end()) + return NULL; - return boost::shared_ptr((*iter).second); + return (*it).second; } void SamplingBar::on_configure() @@ -281,7 +281,7 @@ void SamplingBar::on_configure() sig_hide_calibration(); int ret; - boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); assert(dev_inst); pv::dialogs::DeviceOptions dlg(this, dev_inst); @@ -332,7 +332,7 @@ void SamplingBar::on_configure() void SamplingBar::zero_adj() { boost::shared_ptr dsoSig; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { if ((dsoSig = dynamic_pointer_cast(s))) dsoSig->set_enable(true); @@ -349,14 +349,14 @@ void SamplingBar::zero_adj() pv::dialogs::WaitingDialog wait(this, _session, SR_CONF_ZERO); if (wait.start() == QDialog::Rejected) { - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { if ((dsoSig = dynamic_pointer_cast(s))) dsoSig->commit_settings(); } } - if (_session.get_capture_state() == pv::SigSession::Running) + if (_session->get_capture_state() == pv::SigSession::Running) on_run_stop(); _sample_count.setCurrentIndex(index_back); @@ -399,7 +399,7 @@ void SamplingBar::set_sampling(bool sampling) } else { _run_stop_button.setIcon(sampling ? QIcon(iconPath+"/stop.svg") : QIcon(iconPath+"/start.svg")); } - _mode_button.setIcon(_session.get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : + _mode_button.setIcon(_session->get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : QIcon(iconPath+"/moder.svg")); } @@ -430,7 +430,7 @@ void SamplingBar::update_sample_rate_selector() disconnect(&_sample_rate, SIGNAL(currentIndexChanged(int)), this, SLOT(on_samplerate_sel(int))); - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (!dev_inst) return; @@ -504,7 +504,7 @@ void SamplingBar::update_sample_rate_selector_value() void SamplingBar::on_samplerate_sel(int index) { (void)index; - const boost::shared_ptr dev_inst = get_selected_device(); + const DevInst *dev_inst = get_selected_device(); if (dev_inst->dev_inst()->mode != DSO) update_sample_count_selector(); } @@ -530,7 +530,7 @@ void SamplingBar::update_sample_count_selector() assert(!_updating_sample_count); _updating_sample_count = true; - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_STREAM); if (gvar != NULL) { stream_mode = g_variant_get_boolean(gvar); @@ -546,7 +546,7 @@ void SamplingBar::update_sample_count_selector() #if defined(__x86_64__) || defined(_M_X64) sw_depth = LogicMaxSWDepth64; #elif defined(__i386) || defined(_M_IX86) - int ch_num = _session.get_ch_num(SR_CHANNEL_LOGIC); + int ch_num = _session->get_ch_num(SR_CHANNEL_LOGIC); if (ch_num <= 0) sw_depth = LogicMaxSWDepth32; else @@ -663,7 +663,7 @@ void SamplingBar::update_sample_count_selector_value() GVariant* gvar; double duration; - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (dev_inst->dev_inst()->mode == DSO) { gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TIMEBASE); if (gvar != NULL) { @@ -706,7 +706,7 @@ void SamplingBar::on_samplecount_sel(int index) { (void)index; - const boost::shared_ptr dev_inst = get_selected_device(); + const DevInst *dev_inst = get_selected_device(); if (dev_inst->dev_inst()->mode == DSO) commit_hori_res(); sig_duration_changed(); @@ -744,7 +744,7 @@ double SamplingBar::commit_hori_res() const double hori_res = _sample_count.itemData( _sample_count.currentIndex()).value(); - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); const uint64_t sample_limit = dev_inst->get_sample_limit(); GVariant* gvar; uint64_t max_sample_rate; @@ -760,7 +760,7 @@ double SamplingBar::commit_hori_res() const uint64_t sample_rate = min((uint64_t)(sample_limit * SR_SEC(1) / (hori_res * DS_CONF_DSO_HDIVS)), (uint64_t)(max_sample_rate / - (_session.get_ch_num(SR_CHANNEL_DSO) ? _session.get_ch_num(SR_CHANNEL_DSO) : 1))); + (_session->get_ch_num(SR_CHANNEL_DSO) ? _session->get_ch_num(SR_CHANNEL_DSO) : 1))); set_sample_rate(sample_rate); dev_inst->set_config(NULL, NULL, SR_CONF_TIMEBASE, @@ -772,7 +772,7 @@ double SamplingBar::commit_hori_res() void SamplingBar::commit_settings() { bool test = false; - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (dev_inst && dev_inst->owner()) { GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { @@ -790,7 +790,7 @@ void SamplingBar::commit_settings() const uint64_t sample_rate = _sample_rate.itemData( _sample_rate.currentIndex()).value(); - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (dev_inst) { if (sample_rate != dev_inst->get_sample_rate()) dev_inst->set_config(NULL, NULL, @@ -815,16 +815,18 @@ void SamplingBar::commit_settings() void SamplingBar::on_run_stop() { - if (get_sampling() || _session.isRepeating()) { - _session.exit_capture(); + if (get_sampling() || _session->isRepeating()) { + _session->exit_capture(); } else { enable_run_stop(false); enable_instant(false); commit_settings(); _instant = false; - const boost::shared_ptr dev_inst = get_selected_device(); + + DevInst *dev_inst = get_selected_device(); if (!dev_inst) return; + if (dev_inst->dev_inst()->mode == DSO) { GVariant* gvar = dev_inst->get_config(NULL, NULL, SR_CONF_ZERO); if (gvar != NULL) { @@ -857,9 +859,9 @@ void SamplingBar::on_run_stop() void SamplingBar::on_instant_stop() { if (get_sampling()) { - _session.set_repeating(false); + _session->set_repeating(false); bool wait_upload = false; - if (_session.get_run_mode() != SigSession::Repetitive) { + if (_session->get_run_mode() != SigSession::Repetitive) { GVariant *gvar = get_selected_device()->get_config(NULL, NULL, SR_CONF_WAIT_UPLOAD); if (gvar != NULL) { wait_upload = g_variant_get_boolean(gvar); @@ -867,8 +869,8 @@ void SamplingBar::on_instant_stop() } } if (!wait_upload) { - _session.stop_capture(); - _session.capture_state_changed(SigSession::Stopped); + _session->stop_capture(); + _session->capture_state_changed(SigSession::Stopped); } } else { enable_run_stop(false); @@ -876,7 +878,7 @@ void SamplingBar::on_instant_stop() commit_settings(); _instant = true; - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (!dev_inst) return; @@ -915,15 +917,15 @@ void SamplingBar::on_device_selected() if (_updating_device_selector) return; - _session.stop_capture(); - _session.session_save(); + _session->stop_capture(); + _session->session_save(); - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst* dev_inst = get_selected_device(); if (!dev_inst) return; try { - _session.set_device(dev_inst); + _session->set_device(dev_inst); } catch(QString e) { show_session_error(tr("Failed to select ") + dev_inst->dev_inst()->model, e); } @@ -933,7 +935,7 @@ void SamplingBar::on_device_selected() void SamplingBar::enable_toggle(bool enable) { bool test = false; - const boost::shared_ptr dev_inst = get_selected_device(); + DevInst *dev_inst = get_selected_device(); if (dev_inst && dev_inst->owner()) { GVariant *gvar = dev_inst->get_config(NULL, NULL, SR_CONF_TEST); if (gvar != NULL) { @@ -952,7 +954,7 @@ void SamplingBar::enable_toggle(bool enable) _sample_rate.setDisabled(true); } - if (_session.get_device()->name() == "virtual-session") { + if (_session->get_device()->name() == "virtual-session") { _sample_count.setDisabled(true); _sample_rate.setDisabled(true); } @@ -982,23 +984,23 @@ void SamplingBar::show_session_error( void SamplingBar::reload() { QString iconPath = GetIconPath(); - if (_session.get_device()->dev_inst()->mode == LOGIC) { - if (_session.get_device()->name() == "virtual-session") { + if (_session->get_device()->dev_inst()->mode == LOGIC) { + if (_session->get_device()->name() == "virtual-session") { _mode_action->setVisible(false); } else { - _mode_button.setIcon(_session.get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : + _mode_button.setIcon(_session->get_run_mode() == pv::SigSession::Single ? QIcon(iconPath+"/modes.svg") : QIcon(iconPath+"/moder.svg")); _mode_action->setVisible(true); } _run_stop_action->setVisible(true); _instant_action->setVisible(true); enable_toggle(true); - } else if (_session.get_device()->dev_inst()->mode == ANALOG) { + } else if (_session->get_device()->dev_inst()->mode == ANALOG) { _mode_action->setVisible(false); _run_stop_action->setVisible(true); _instant_action->setVisible(false); enable_toggle(true); - } else if (_session.get_device()->dev_inst()->mode == DSO) { + } else if (_session->get_device()->dev_inst()->mode == DSO) { _mode_action->setVisible(false); _run_stop_action->setVisible(true); _instant_action->setVisible(true); @@ -1016,12 +1018,12 @@ void SamplingBar::on_mode() QAction *act = qobject_cast(sender()); if (act == _action_single) { _mode_button.setIcon(QIcon(iconPath+"/modes.svg")); - _session.set_run_mode(pv::SigSession::Single); + _session->set_run_mode(pv::SigSession::Single); } else if (act == _action_repeat) { _mode_button.setIcon(QIcon(iconPath+"/moder.svg")); pv::dialogs::Interval interval_dlg(_session, this); interval_dlg.exec(); - _session.set_run_mode(pv::SigSession::Repetitive); + _session->set_run_mode(pv::SigSession::Repetitive); } } diff --git a/DSView/pv/toolbars/samplingbar.h b/DSView/pv/toolbars/samplingbar.h index ee3ce6d8..f4addaef 100755 --- a/DSView/pv/toolbars/samplingbar.h +++ b/DSView/pv/toolbars/samplingbar.h @@ -45,7 +45,7 @@ namespace pv namespace device { - // class DevInst; + class DevInst; } namespace dialogs @@ -72,12 +72,11 @@ namespace pv static const uint64_t ZeroTimeBase = SR_US(2); public: - SamplingBar(SigSession &session, QWidget *parent); + SamplingBar(SigSession *session, QWidget *parent); - void set_device_list(const std::list> &devices, - boost::shared_ptr selected); + void set_device_list(const std::list &devices, DevInst* selected); - boost::shared_ptr get_selected_device() const; + DevInst *get_selected_device() const; void update_sample_rate_selector(); @@ -135,7 +134,7 @@ namespace pv void reload(); private: - SigSession &_session; + SigSession *_session; mutable boost::recursive_mutex _sampling_mutex; bool _enable; @@ -144,8 +143,7 @@ namespace pv QToolButton _device_type; QComboBox _device_selector; - std::map> - _device_selector_map; + std::map _device_selector_map; bool _updating_device_selector; QToolButton _configure_button; diff --git a/DSView/pv/toolbars/trigbar.cpp b/DSView/pv/toolbars/trigbar.cpp index 7fa25e17..ea5f7c8e 100755 --- a/DSView/pv/toolbars/trigbar.cpp +++ b/DSView/pv/toolbars/trigbar.cpp @@ -38,7 +38,7 @@ namespace toolbars { const QString TrigBar::DARK_STYLE = "dark"; const QString TrigBar::LIGHT_STYLE = "light"; -TrigBar::TrigBar(SigSession &session, QWidget *parent) : +TrigBar::TrigBar(SigSession *session, QWidget *parent) : QToolBar("Trig Bar", parent), _session(session), _enable(true), @@ -261,21 +261,21 @@ void TrigBar::close_all() void TrigBar::reload() { close_all(); - if (_session.get_device()->dev_inst()->mode == LOGIC) { + if (_session->get_device()->dev_inst()->mode == LOGIC) { _trig_action->setVisible(true); _protocol_action->setVisible(true); _measure_action->setVisible(true); _search_action->setVisible(true); _function_action->setVisible(false); _action_lissajous->setVisible(false); - } else if (_session.get_device()->dev_inst()->mode == ANALOG) { + } else if (_session->get_device()->dev_inst()->mode == ANALOG) { _trig_action->setVisible(false); _protocol_action->setVisible(false); _measure_action->setVisible(true); _search_action->setVisible(false); _function_action->setVisible(false); _action_lissajous->setVisible(false); - } else if (_session.get_device()->dev_inst()->mode == DSO) { + } else if (_session->get_device()->dev_inst()->mode == DSO) { _trig_action->setVisible(true); _protocol_action->setVisible(false); _measure_action->setVisible(true); diff --git a/DSView/pv/toolbars/trigbar.h b/DSView/pv/toolbars/trigbar.h index 58f07f05..f22ce207 100755 --- a/DSView/pv/toolbars/trigbar.h +++ b/DSView/pv/toolbars/trigbar.h @@ -45,7 +45,7 @@ protected: static const QString LIGHT_STYLE; public: - explicit TrigBar(SigSession &session, QWidget *parent = 0); + explicit TrigBar(SigSession *session, QWidget *parent = 0); void enable_toggle(bool enable); void enable_protocol(bool enable); @@ -86,8 +86,8 @@ public slots: void on_application_param(); private: - SigSession& _session; - bool _enable; + SigSession *_session; + bool _enable; QToolButton _trig_button; QToolButton _protocol_button; QToolButton _measure_button; diff --git a/DSView/pv/view/analogsignal.cpp b/DSView/pv/view/analogsignal.cpp index 2460fe5e..605566ac 100755 --- a/DSView/pv/view/analogsignal.cpp +++ b/DSView/pv/view/analogsignal.cpp @@ -47,7 +47,7 @@ const QColor AnalogSignal::SignalColours[4] = { const float AnalogSignal::EnvelopeThreshold = 16.0f; -AnalogSignal::AnalogSignal(boost::shared_ptr dev_inst, +AnalogSignal::AnalogSignal(DevInst *dev_inst, boost::shared_ptr data, sr_channel *probe) : Signal(dev_inst, probe), diff --git a/DSView/pv/view/analogsignal.h b/DSView/pv/view/analogsignal.h index 94e29290..401351eb 100755 --- a/DSView/pv/view/analogsignal.h +++ b/DSView/pv/view/analogsignal.h @@ -53,7 +53,7 @@ private: static const uint8_t DefaultBits = 8; public: - AnalogSignal(boost::shared_ptr dev_inst, + AnalogSignal(DevInst* dev_inst, boost::shared_ptr data, sr_channel *probe); AnalogSignal(boost::shared_ptr s, diff --git a/DSView/pv/view/decodetrace.cpp b/DSView/pv/view/decodetrace.cpp index 0fa24f1a..b81be63e 100755 --- a/DSView/pv/view/decodetrace.cpp +++ b/DSView/pv/view/decodetrace.cpp @@ -115,7 +115,7 @@ const QColor DecodeTrace::OutlineColours[16] = { const QString DecodeTrace::RegionStart = QT_TR_NOOP("Start"); const QString DecodeTrace::RegionEnd = QT_TR_NOOP("End "); -DecodeTrace::DecodeTrace(pv::SigSession &session, +DecodeTrace::DecodeTrace(pv::SigSession *session, boost::shared_ptr decoder_stack, int index) : Trace(QString::fromUtf8( decoder_stack->stack().front()->decoder()->name), index, SR_CHANNEL_DECODER), @@ -181,7 +181,7 @@ void DecodeTrace::paint_back(QPainter &p, int left, int right, QColor fore, QCol p.drawLine(left, sigY, right, sigY); // --draw decode region control - const double samples_per_pixel = _session.cur_snap_samplerate() * _view->scale(); + const double samples_per_pixel = _session->cur_snap_samplerate() * _view->scale(); const double startX = _decode_start/samples_per_pixel - _view->offset(); const double endX = _decode_end/samples_per_pixel - _view->offset(); const double regionY = get_y() - _totalHeight*0.5 - ControlRectWidth; @@ -534,7 +534,7 @@ void DecodeTrace::draw_annotation(const pv::data::decode::Annotation &a, ((type%100 != a.type()%100) && (type%100 != 0))) continue; boost::shared_ptr logic_sig; - BOOST_FOREACH(boost::shared_ptr sig, _session.get_signals()) { + BOOST_FOREACH(boost::shared_ptr sig, _session->get_signals()) { if((sig->get_index() == iter.second) && (logic_sig = dynamic_pointer_cast(sig))) { logic_sig->paint_mark(p, start, end, type/100); @@ -773,7 +773,7 @@ QComboBox* DecodeTrace::create_probe_selector( { assert(dec); - const vector< boost::shared_ptr > sigs(_session.get_signals()); + const vector< boost::shared_ptr > sigs(_session->get_signals()); assert(_decoder_stack); const map::const_iterator probe_iter = @@ -809,7 +809,7 @@ void DecodeTrace::commit_decoder_probes(boost::shared_ptr assert(dec); map probe_map; - const vector< boost::shared_ptr > sigs(_session.get_signals()); + const vector< boost::shared_ptr > sigs(_session->get_signals()); _index_list.clear(); BOOST_FOREACH(const ProbeSelector &s, _probe_selectors) @@ -873,12 +873,12 @@ void DecodeTrace::on_decode_done() // _view->signals_changed(); // } on_new_decode_data(); - _session.decode_done(); + _session->decode_done(); } void DecodeTrace::on_delete() { - _session.remove_decode_signal(this); + _session->remove_decode_signal(this); } void DecodeTrace::on_probe_selected(int) @@ -971,7 +971,7 @@ QRectF DecodeTrace::get_rect(DecodeSetRegions type, int y, int right) void DecodeTrace::on_region_set(int index) { (void)index; - const uint64_t last_samples = _session.cur_samplelimits() - 1; + const uint64_t last_samples = _session->cur_samplelimits() - 1; const int index1 = _start_comboBox->currentIndex(); const int index2 = _end_comboBox->currentIndex(); uint64_t decode_start, decode_end; @@ -1008,7 +1008,7 @@ void DecodeTrace::on_region_set(int index) void DecodeTrace::frame_ended() { - const uint64_t last_samples = _session.cur_samplelimits() - 1; + const uint64_t last_samples = _session->cur_samplelimits() - 1; if (_decode_start > last_samples) { _decode_start = 0; _start_index = 0; diff --git a/DSView/pv/view/decodetrace.h b/DSView/pv/view/decodetrace.h index 924cf333..ee2ae804 100755 --- a/DSView/pv/view/decodetrace.h +++ b/DSView/pv/view/decodetrace.h @@ -97,7 +97,7 @@ private: static const QString RegionEnd; public: - DecodeTrace(pv::SigSession &session, + DecodeTrace(pv::SigSession *session, boost::shared_ptr decoder_stack, int index); ~DecodeTrace(); @@ -206,7 +206,7 @@ private slots: void on_region_set(int index); private: - pv::SigSession &_session; + pv::SigSession *_session; boost::shared_ptr _decoder_stack; uint64_t _decode_start, _decode_end; diff --git a/DSView/pv/view/devmode.cpp b/DSView/pv/view/devmode.cpp index 2c99e95b..05659b20 100755 --- a/DSView/pv/view/devmode.cpp +++ b/DSView/pv/view/devmode.cpp @@ -43,7 +43,7 @@ using namespace std; namespace pv { namespace view { -DevMode::DevMode(QWidget *parent, SigSession &session) : +DevMode::DevMode(QWidget *parent, SigSession *session) : QWidget(parent), _session(session) @@ -91,7 +91,7 @@ void DevMode::changeEvent(QEvent *event) void DevMode::set_device() { - const boost::shared_ptr dev_inst = _session.get_device(); + DevInst* dev_inst = _session->get_device(); assert(dev_inst); for(std::map::const_iterator i = _mode_list.begin(); @@ -134,8 +134,8 @@ void DevMode::set_device() _pop_menu->addAction(action); } - boost::shared_ptr file_dev; - if((file_dev = dynamic_pointer_cast(dev_inst))) { + File *file_dev; + if((file_dev = dynamic_cast(dev_inst))) { _close_button->setDisabled(false); _close_button->setIcon(QIcon(iconPath+"/close.svg")); connect(_close_button, SIGNAL(clicked()), this, SLOT(on_close())); @@ -156,7 +156,7 @@ void DevMode::paintEvent(QPaintEvent*) void DevMode::on_mode_change() { - const boost::shared_ptr dev_inst = _session.get_device(); + DevInst* dev_inst = _session->get_device(); assert(dev_inst); QAction *action = qobject_cast(sender()); if (dev_inst->dev_inst()->mode == _mode_list[action]->mode) @@ -170,11 +170,11 @@ void DevMode::on_mode_change() i != _mode_list.end(); i++) { if ((*i).first == action) { if (dev_inst->dev_inst()->mode != (*i).second->mode) { - _session.set_run_mode(SigSession::Single); - _session.set_repeating(false); - _session.stop_capture(); - _session.capture_state_changed(SigSession::Stopped); - _session.session_save(); + _session->set_run_mode(SigSession::Single); + _session->set_repeating(false); + _session->stop_capture(); + _session->capture_state_changed(SigSession::Stopped); + _session->session_save(); dev_inst->set_config(NULL, NULL, SR_CONF_DEVICE_MODE, g_variant_new_int16((*i).second->mode)); @@ -193,10 +193,10 @@ void DevMode::on_mode_change() void DevMode::on_close() { - const boost::shared_ptr dev_inst = _session.get_device(); + DevInst *dev_inst = _session->get_device(); assert(dev_inst); - _session.close_file(dev_inst); + _session->close_file(dev_inst); dev_changed(true); } diff --git a/DSView/pv/view/devmode.h b/DSView/pv/view/devmode.h index 6dc2f5d9..ae26e53c 100755 --- a/DSView/pv/view/devmode.h +++ b/DSView/pv/view/devmode.h @@ -59,7 +59,7 @@ private: static const int GRID_COLS = 3; public: - DevMode(QWidget *parent, SigSession &session); + DevMode(QWidget *parent, SigSession *ession); private: void paintEvent(QPaintEvent *event); @@ -83,7 +83,7 @@ signals: void dev_changed(bool close); private: - SigSession &_session; + SigSession *_session; QHBoxLayout * _layout; std::map _mode_list; diff --git a/DSView/pv/view/dsosignal.cpp b/DSView/pv/view/dsosignal.cpp index a359acad..615f2d31 100755 --- a/DSView/pv/view/dsosignal.cpp +++ b/DSView/pv/view/dsosignal.cpp @@ -56,7 +56,7 @@ const QColor DsoSignal::SignalColours[4] = { const float DsoSignal::EnvelopeThreshold = 256.0f; -DsoSignal::DsoSignal(boost::shared_ptr dev_inst, +DsoSignal::DsoSignal(DevInst *dev_inst, boost::shared_ptr data, sr_channel *probe): Signal(dev_inst, probe), diff --git a/DSView/pv/view/dsosignal.h b/DSView/pv/view/dsosignal.h index a6f28ec2..50d079a9 100755 --- a/DSView/pv/view/dsosignal.h +++ b/DSView/pv/view/dsosignal.h @@ -87,7 +87,7 @@ private: static const uint16_t MS_RectHeight = 25; public: - DsoSignal(boost::shared_ptr dev_inst, + DsoSignal(DevInst* dev_inst, boost::shared_ptr data, sr_channel *probe); diff --git a/DSView/pv/view/logicsignal.cpp b/DSView/pv/view/logicsignal.cpp index 95d57b67..e336dc4a 100755 --- a/DSView/pv/view/logicsignal.cpp +++ b/DSView/pv/view/logicsignal.cpp @@ -45,7 +45,7 @@ const float LogicSignal::Oversampling = 1.0f; const int LogicSignal::StateHeight = 12; const int LogicSignal::StateRound = 5; -LogicSignal::LogicSignal(boost::shared_ptr dev_inst, +LogicSignal::LogicSignal(DevInst *dev_inst, boost::shared_ptr data, sr_channel *probe) : Signal(dev_inst, probe), diff --git a/DSView/pv/view/logicsignal.h b/DSView/pv/view/logicsignal.h index c9377c8a..d2159eb5 100755 --- a/DSView/pv/view/logicsignal.h +++ b/DSView/pv/view/logicsignal.h @@ -37,6 +37,8 @@ class Logic; class Analog; } +using namespace pv::device; + namespace view { //when device is logic analyzer mode, to draw logic signal trace @@ -64,7 +66,7 @@ public: }; public: - LogicSignal(boost::shared_ptr dev_inst, + LogicSignal(DevInst *dev_inst, boost::shared_ptr data, sr_channel *probe); diff --git a/DSView/pv/view/signal.cpp b/DSView/pv/view/signal.cpp index 0646cb06..3be6142d 100755 --- a/DSView/pv/view/signal.cpp +++ b/DSView/pv/view/signal.cpp @@ -32,8 +32,7 @@ namespace pv { namespace view { -Signal::Signal(boost::shared_ptr dev_inst, - sr_channel *probe) : +Signal::Signal(DevInst *dev_inst,sr_channel *probe) : Trace(probe->name, probe->index, probe->type), _dev_inst(dev_inst), _probe(probe) @@ -59,7 +58,7 @@ void Signal::set_name(QString name) _probe->name = g_strdup(name.toUtf8().data()); } -boost::shared_ptr Signal::get_device() const +DevInst* Signal::get_device() const { return _dev_inst; } diff --git a/DSView/pv/view/signal.h b/DSView/pv/view/signal.h index ff7eb5b0..1d3ed5ad 100755 --- a/DSView/pv/view/signal.h +++ b/DSView/pv/view/signal.h @@ -48,6 +48,8 @@ namespace device { class DevInst; } +using namespace pv::device; + namespace view { //draw signal trace base class @@ -59,8 +61,7 @@ private: protected: - Signal(boost::shared_ptr dev_inst, - sr_channel * const probe); + Signal(DevInst* dev_inst,sr_channel * const probe); /** * Copy constructor @@ -90,10 +91,10 @@ public: */ //virtual void paint_label(QPainter &p, int right, bool hover, int action); - boost::shared_ptr get_device() const; + DevInst* get_device() const; protected: - boost::shared_ptr _dev_inst; + DevInst* _dev_inst; sr_channel *const _probe; }; diff --git a/DSView/pv/view/spectrumtrace.cpp b/DSView/pv/view/spectrumtrace.cpp index 4be12280..64500c52 100755 --- a/DSView/pv/view/spectrumtrace.cpp +++ b/DSView/pv/view/spectrumtrace.cpp @@ -67,7 +67,7 @@ const int SpectrumTrace::DbvRanges[4] = { const int SpectrumTrace::HoverPointSize = 3; const double SpectrumTrace::VerticalRate = 1.0 / 2000.0; -SpectrumTrace::SpectrumTrace(pv::SigSession &session, +SpectrumTrace::SpectrumTrace(pv::SigSession *session, boost::shared_ptr spectrum_stack, int index) : Trace("FFT("+QString::number(index)+")", index, SR_CHANNEL_FFT), _session(session), @@ -79,7 +79,7 @@ SpectrumTrace::SpectrumTrace(pv::SigSession &session, _offset(0) { _typeWidth = 0; - const vector< boost::shared_ptr > sigs(_session.get_signals()); + const vector< boost::shared_ptr > sigs(_session->get_signals()); for(size_t i = 0; i < sigs.size(); i++) { const boost::shared_ptr s(sigs[i]); assert(s); @@ -294,7 +294,7 @@ void SpectrumTrace::paint_mid(QPainter &p, int left, int right, QColor fore, QCo double vdiv = 0; double vfactor = 0; - BOOST_FOREACH(const boost::shared_ptr s, _session.get_signals()) { + BOOST_FOREACH(const boost::shared_ptr s, _session->get_signals()) { boost::shared_ptr dsoSig; if ((dsoSig = dynamic_pointer_cast(s))) { if(dsoSig->get_index() == _spectrum_stack->get_index()) { @@ -364,8 +364,8 @@ void SpectrumTrace::paint_fore(QPainter &p, int left, int right, QColor fore, QC double blank_right = width; // horizontal ruler - const double NyFreq = _session.cur_snap_samplerate() / (2.0 * _spectrum_stack->get_sample_interval()); - const double deltaFreq = _session.cur_snap_samplerate() * 1.0 / + const double NyFreq = _session->cur_snap_samplerate() / (2.0 * _spectrum_stack->get_sample_interval()); + const double deltaFreq = _session->cur_snap_samplerate() * 1.0 / (_spectrum_stack->get_sample_num() * _spectrum_stack->get_sample_interval()); const double FreqRange = NyFreq * _scale; const double FreqOffset = NyFreq * _offset; diff --git a/DSView/pv/view/spectrumtrace.h b/DSView/pv/view/spectrumtrace.h index 7173188b..293269ef 100755 --- a/DSView/pv/view/spectrumtrace.h +++ b/DSView/pv/view/spectrumtrace.h @@ -67,7 +67,7 @@ private: static const double VerticalRate; public: - SpectrumTrace(pv::SigSession &session, + SpectrumTrace(pv::SigSession *session, boost::shared_ptr spectrum_stack, int index); ~SpectrumTrace(); @@ -133,7 +133,7 @@ private: private slots: private: - pv::SigSession &_session; + pv::SigSession *_session; boost::shared_ptr _spectrum_stack; bool _enable; diff --git a/DSView/pv/view/view.cpp b/DSView/pv/view/view.cpp index 349f0b6b..d9bb13d1 100755 --- a/DSView/pv/view/view.cpp +++ b/DSView/pv/view/view.cpp @@ -79,7 +79,7 @@ const QColor View::LightBlue = QColor(17, 133, 209, 200); const QColor View::LightRed = QColor(213, 15, 37, 200); -View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget *parent) : +View::View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget *parent) : QScrollArea(parent), _session(session), _sampling_bar(sampling_bar), @@ -98,7 +98,9 @@ View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget _dso_auto(true), _show_lissajous(false), _back_ready(false) -{ +{ + assert(session); + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), @@ -165,23 +167,23 @@ View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget connect(_vsplitter, SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMoved(int, int))); - connect(&_session, SIGNAL(device_setted()), + connect(_session, SIGNAL(device_setted()), _devmode, SLOT(set_device())); - connect(&_session, SIGNAL(signals_changed()), + connect(_session, SIGNAL(signals_changed()), this, SLOT(signals_changed()), Qt::DirectConnection); - connect(&_session, SIGNAL(data_updated()), + connect(_session, SIGNAL(data_updated()), this, SLOT(data_updated())); - connect(&_session, SIGNAL(receive_trigger(quint64)), + connect(_session, SIGNAL(receive_trigger(quint64)), this, SLOT(receive_trigger(quint64))); - connect(&_session, SIGNAL(frame_ended()), + connect(_session, SIGNAL(frame_ended()), this, SLOT(receive_end())); - connect(&_session, SIGNAL(frame_began()), + connect(_session, SIGNAL(frame_began()), this, SLOT(frame_began())); - connect(&_session, SIGNAL(show_region(uint64_t, uint64_t, bool)), + connect(_session, SIGNAL(show_region(uint64_t, uint64_t, bool)), this, SLOT(show_region(uint64_t, uint64_t, bool))); - connect(&_session, SIGNAL(show_wait_trigger()), + connect(_session, SIGNAL(show_wait_trigger()), _time_viewport, SLOT(show_wait_trigger())); - connect(&_session, SIGNAL(repeat_hold(int)), + connect(_session, SIGNAL(repeat_hold(int)), this, SLOT(repeat_show())); connect(_devmode, SIGNAL(dev_changed(bool)), @@ -217,7 +219,7 @@ View::View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget SigSession& View::session() { - return _session; + return *_session; } double View::scale() const @@ -252,13 +254,13 @@ double View::get_maxscale() const void View::capture_init() { - if (_session.get_device()->dev_inst()->mode == DSO) + if (_session->get_device()->dev_inst()->mode == DSO) show_trig_cursor(true); - else if (!_session.isRepeating()) + else if (!_session->isRepeating()) show_trig_cursor(false); - _maxscale = _session.cur_sampletime() / (get_view_width() * MaxViewRate); - if (_session.get_device()->dev_inst()->mode == ANALOG) + _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); + if (_session->get_device()->dev_inst()->mode == ANALOG) set_scale_offset(_maxscale, 0); status_clear(); _trig_time_setted = false; @@ -288,7 +290,7 @@ double View::get_hori_res() void View::update_hori_res() { - if (_session.get_device()->dev_inst()->mode == DSO) { + if (_session->get_device()->dev_inst()->mode == DSO) { _sampling_bar->hori_knob(0); } } @@ -299,12 +301,12 @@ bool View::zoom(double steps, int offset) _preScale = _scale; _preOffset = _offset; - if (_session.get_device()->dev_inst()->mode != DSO) { + if (_session->get_device()->dev_inst()->mode != DSO) { _scale *= std::pow(3.0/2.0, -steps); _scale = max(min(_scale, _maxscale), _minscale); } else { - if (_session.get_capture_state() == SigSession::Running && - _session.get_instant()) + if (_session->get_capture_state() == SigSession::Running && + _session->get_instant()) return ret; double hori_res = -1; @@ -314,7 +316,7 @@ bool View::zoom(double steps, int offset) hori_res = _sampling_bar->hori_knob(1); if (hori_res > 0) { - const double scale = _session.cur_view_time() / get_view_width(); + const double scale = _session->cur_view_time() / get_view_width(); _scale = max(min(scale, _maxscale), _minscale); } else { ret = false; @@ -336,19 +338,19 @@ bool View::zoom(double steps, int offset) void View::timebase_changed() { - if (_session.get_device()->dev_inst()->mode != DSO) + if (_session->get_device()->dev_inst()->mode != DSO) return; double scale = this->scale(); double hori_res = _sampling_bar->get_hori_res(); if (hori_res > 0) - scale = _session.cur_view_time() / get_view_width(); + scale = _session->cur_view_time() / get_view_width(); set_scale_offset(scale, this->offset()); } void View::set_scale_offset(double scale, int64_t offset) { - //if (_session.get_capture_state() == SigSession::Stopped) { + //if (_session->get_capture_state() == SigSession::Stopped) { _preScale = _scale; _preOffset = _offset; @@ -375,13 +377,16 @@ void View::set_preScale_preOffset() vector< boost::shared_ptr > View::get_traces(int type) { - const vector< boost::shared_ptr > sigs(_session.get_signals()); - const vector< boost::shared_ptr > groups(_session.get_group_signals()); + assert(_session); + + auto array = _session->get_signals(); + const vector< boost::shared_ptr > sigs(array); + const vector< boost::shared_ptr > groups(_session->get_group_signals()); const vector< boost::shared_ptr > decode_sigs( - _session.get_decode_signals()); + _session->get_decode_signals()); - const vector< boost::shared_ptr > spectrums(_session.get_spectrum_traces()); + const vector< boost::shared_ptr > spectrums(_session->get_spectrum_traces()); vector< boost::shared_ptr > traces; BOOST_FOREACH(boost::shared_ptr t, sigs) { @@ -404,12 +409,12 @@ vector< boost::shared_ptr > View::get_traces(int type) traces.push_back(t); } - boost::shared_ptr lissajous = _session.get_lissajous_trace(); + boost::shared_ptr lissajous = _session->get_lissajous_trace(); if (lissajous && lissajous->enabled() && (type == ALL_VIEW || _trace_view_map[lissajous->get_type()] == type)) traces.push_back(lissajous); - boost::shared_ptr math = _session.get_math_trace(); + boost::shared_ptr math = _session->get_math_trace(); if (math && math->enabled() && (type == ALL_VIEW || _trace_view_map[math->get_type()] == type)) traces.push_back(math); @@ -481,8 +486,8 @@ void View::repeat_unshow() void View::frame_began() { -// if (_session.get_device()->dev_inst()->mode == LOGIC) -// _viewbottom->set_trig_time(_session.get_session_time()); +// if (_session->get_device()->dev_inst()->mode == LOGIC) +// _viewbottom->set_trig_time(_session->get_session_time()); _search_hit = false; _search_pos = 0; set_search_pos(_search_pos, _search_hit); @@ -490,9 +495,9 @@ void View::frame_began() void View::set_trig_time() { - if (!_trig_time_setted && _session.get_device()->dev_inst()->mode == LOGIC) { - _session.set_session_time(QDateTime::currentDateTime()); - _viewbottom->set_trig_time(_session.get_session_time()); + if (!_trig_time_setted && _session->get_device()->dev_inst()->mode == LOGIC) { + _session->set_session_time(QDateTime::currentDateTime()); + _viewbottom->set_trig_time(_session->get_session_time()); } _trig_time_setted = true; } @@ -504,17 +509,17 @@ bool View::trig_time_setted() void View::receive_end() { - if (_session.get_device()->dev_inst()->mode == LOGIC) { - GVariant *gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_RLE); + if (_session->get_device()->dev_inst()->mode == LOGIC) { + GVariant *gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_RLE); if (gvar != NULL) { bool rle = g_variant_get_boolean(gvar); g_variant_unref(gvar); if (rle) { - gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_ACTUAL_SAMPLES); + gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_ACTUAL_SAMPLES); if (gvar != NULL) { uint64_t actual_samples = g_variant_get_uint64(gvar); g_variant_unref(gvar); - if (actual_samples != _session.cur_samplelimits()) { + if (actual_samples != _session->cur_samplelimits()) { _viewbottom->set_rle_depth(actual_samples); } } @@ -526,11 +531,11 @@ void View::receive_end() void View::receive_trigger(quint64 trig_pos) { - const double time = trig_pos * 1.0 / _session.cur_snap_samplerate(); + const double time = trig_pos * 1.0 / _session->cur_snap_samplerate(); _trig_cursor->set_index(trig_pos); if (ds_trigger_get_en() || - _session.get_device()->name() == "virtual-session" || - _session.get_device()->dev_inst()->mode == DSO) { + _session->get_device()->name() == "virtual-session" || + _session->get_device()->dev_inst()->mode == DSO) { _show_trig_cursor = true; set_scale_offset(_scale, (time / _scale) - (get_view_width() / 2)); } @@ -541,7 +546,7 @@ void View::receive_trigger(quint64 trig_pos) void View::set_trig_pos(int percent) { - uint64_t index = _session.cur_samplelimits() * percent / 100; + uint64_t index = _session->cur_samplelimits() * percent / 100; receive_trigger(index); } @@ -551,7 +556,7 @@ void View::set_search_pos(uint64_t search_pos, bool hit) QColor fore(QWidget::palette().color(QWidget::foregroundRole())); fore.setAlpha(View::BackAlpha); - const double time = search_pos * 1.0 / _session.cur_snap_samplerate(); + const double time = search_pos * 1.0 / _session->cur_snap_samplerate(); _search_pos = search_pos; _search_hit = hit; _search_cursor->set_index(search_pos); @@ -608,11 +613,11 @@ int View::get_signalHeight() void View::get_scroll_layout(int64_t &length, int64_t &offset) const { - const set< boost::shared_ptr > data_set = _session.get_data(); + const set< boost::shared_ptr > data_set = _session->get_data(); if (data_set.empty()) return; - length = ceil(_session.cur_snap_sampletime() / _scale); + length = ceil(_session->cur_snap_sampletime() / _scale); offset = _offset; } @@ -650,11 +655,11 @@ void View::update_scroll() void View::update_scale_offset() { - if (_session.get_device()->dev_inst()->mode != DSO) { - _maxscale = _session.cur_sampletime() / (get_view_width() * MaxViewRate); - _minscale = (1.0 / _session.cur_snap_samplerate()) / MaxPixelsPerSample; + if (_session->get_device()->dev_inst()->mode != DSO) { + _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); + _minscale = (1.0 / _session->cur_snap_samplerate()) / MaxPixelsPerSample; } else { - _scale = _session.cur_view_time() / get_view_width(); + _scale = _session->cur_view_time() / get_view_width(); _maxscale = 1e9; _minscale = 1e-15; } @@ -665,7 +670,7 @@ void View::update_scale_offset() _preScale = _scale; _preOffset = _offset; - //_trig_cursor->set_index(_session.get_trigger_pos()); + //_trig_cursor->set_index(_session->get_trigger_pos()); _ruler->update(); viewport_update(); @@ -674,8 +679,8 @@ void View::update_scale_offset() void View::dev_changed(bool close) { if (!close) { - if (_session.get_device()->name().contains("virtual")) - _scale = WellSamplesPerPixel * 1.0 / _session.cur_snap_samplerate(); + if (_session->get_device()->name().contains("virtual")) + _scale = WellSamplesPerPixel * 1.0 / _session->cur_snap_samplerate(); _scale = max(min(_scale, _maxscale), _minscale); } @@ -739,8 +744,8 @@ void View::signals_changed() const double height = (_time_viewport->height() - 2 * actualMargin * label_size) * 1.0 / total_rows; - if (_session.get_device()->dev_inst()->mode == LOGIC) { - GVariant* gvar = _session.get_device()->get_config(NULL, NULL, SR_CONF_MAX_HEIGHT_VALUE); + if (_session->get_device()->dev_inst()->mode == LOGIC) { + GVariant* gvar = _session->get_device()->get_config(NULL, NULL, SR_CONF_MAX_HEIGHT_VALUE); if (gvar != NULL) { max_height = (g_variant_get_byte(gvar) + 1) * MaxHeightUnit; g_variant_unref(gvar); @@ -752,7 +757,7 @@ void View::signals_changed() } else { _signalHeight = (height >= max_height) ? max_height : height; } - } else if (_session.get_device()->dev_inst()->mode == DSO) { + } else if (_session->get_device()->dev_inst()->mode == DSO) { _signalHeight = (_header->height() - horizontalScrollBar()->height() - 2 * actualMargin * label_size) * 1.0 / total_rows; @@ -800,7 +805,7 @@ bool View::eventFilter(QObject *object, QEvent *event) double cur_periods = (mouse_event->pos().x() + _offset) * _scale / _ruler->get_min_period(); int integer_x = round(cur_periods) * _ruler->get_min_period() / _scale - _offset; double cur_deviate_x = qAbs(mouse_event->pos().x() - integer_x); - if (_session.get_device()->dev_inst()->mode == LOGIC && + if (_session->get_device()->dev_inst()->mode == LOGIC && cur_deviate_x < 10) _hover_point = QPoint(integer_x, mouse_event->pos().y()); else @@ -859,11 +864,11 @@ void View::resizeEvent(QResizeEvent*) update_margins(); update_scroll(); signals_changed(); - if (_session.get_device()->dev_inst()->mode == DSO) - _scale = _session.cur_view_time() / get_view_width(); + if (_session->get_device()->dev_inst()->mode == DSO) + _scale = _session->cur_view_time() / get_view_width(); - if (_session.get_device()->dev_inst()->mode != DSO) - _maxscale = _session.cur_sampletime() / (get_view_width() * MaxViewRate); + if (_session->get_device()->dev_inst()->mode != DSO) + _maxscale = _session->cur_sampletime() / (get_view_width() * MaxViewRate); else _maxscale = 1e9; @@ -1008,7 +1013,7 @@ void View::set_cursor_middle(int index) list::iterator i = _cursorList.begin(); while (index-- != 0) i++; - set_scale_offset(_scale, (*i)->index() / (_session.cur_snap_samplerate() * _scale) - (get_view_width() / 2)); + set_scale_offset(_scale, (*i)->index() / (_session->cur_snap_samplerate() * _scale) - (get_view_width() / 2)); } void View::on_measure_updated() @@ -1027,7 +1032,7 @@ QString View::get_measure(QString option) QString View::get_cm_time(int index) { - return _ruler->format_real_time(get_cursor_samples(index), _session.cur_snap_samplerate()); + return _ruler->format_real_time(get_cursor_samples(index), _session->cur_snap_samplerate()); } QString View::get_cm_delta(int index1, int index2) @@ -1038,7 +1043,7 @@ QString View::get_cm_delta(int index1, int index2) uint64_t samples1 = get_cursor_samples(index1); uint64_t samples2 = get_cursor_samples(index2); uint64_t delta_sample = (samples1 > samples2) ? samples1 - samples2 : samples2 - samples1; - return _ruler->format_real_time(delta_sample, _session.cur_snap_samplerate()); + return _ruler->format_real_time(delta_sample, _session->cur_snap_samplerate()); } QString View::get_index_delta(uint64_t start, uint64_t end) @@ -1047,7 +1052,7 @@ QString View::get_index_delta(uint64_t start, uint64_t end) return "0"; uint64_t delta_sample = (start > end) ? start - end : end - start; - return _ruler->format_real_time(delta_sample, _session.cur_snap_samplerate()); + return _ruler->format_real_time(delta_sample, _session->cur_snap_samplerate()); } uint64_t View::get_cursor_samples(int index) @@ -1083,8 +1088,8 @@ void View::on_state_changed(bool stop) QRect View::get_view_rect() { - if (_session.get_device()->dev_inst()->mode == DSO) { - const vector< boost::shared_ptr > sigs(_session.get_signals()); + if (_session->get_device()->dev_inst()->mode == DSO) { + const vector< boost::shared_ptr > sigs(_session->get_signals()); BOOST_FOREACH(const boost::shared_ptr s, sigs) { return s->get_view_rect(); } @@ -1096,8 +1101,8 @@ QRect View::get_view_rect() int View::get_view_width() { int view_width = 0; - if (_session.get_device()->dev_inst()->mode == DSO) { - const vector< boost::shared_ptr > sigs(_session.get_signals()); + if (_session->get_device()->dev_inst()->mode == DSO) { + const vector< boost::shared_ptr > sigs(_session->get_signals()); BOOST_FOREACH(const boost::shared_ptr s, sigs) { view_width = max(view_width, s->get_view_rect().width()); } @@ -1111,8 +1116,8 @@ int View::get_view_width() int View::get_view_height() { int view_height = 0; - if (_session.get_device()->dev_inst()->mode == DSO) { - const vector< boost::shared_ptr > sigs(_session.get_signals()); + if (_session->get_device()->dev_inst()->mode == DSO) { + const vector< boost::shared_ptr > sigs(_session->get_signals()); BOOST_FOREACH(const boost::shared_ptr s, sigs) { view_height = max(view_height, s->get_view_rect().height()); } @@ -1133,14 +1138,14 @@ int64_t View::get_min_offset() int64_t View::get_max_offset() { - return ceil((_session.cur_snap_sampletime() / _scale) - + return ceil((_session->cur_snap_sampletime() / _scale) - (get_view_width() * MaxViewRate)); } // -- calibration dialog void View::show_calibration() { - _cali->set_device(_session.get_device()); + _cali->set_device(_session->get_device()); _cali->show(); } @@ -1152,9 +1157,9 @@ void View::hide_calibration() void View::vDial_updated() { if (_cali->isVisible()) { - _cali->set_device(_session.get_device()); + _cali->set_device(_session->get_device()); } - boost::shared_ptr math_trace = _session.get_math_trace(); + boost::shared_ptr math_trace = _session->get_math_trace(); if (math_trace && math_trace->enabled()) { math_trace->update_vDial(); } @@ -1173,14 +1178,14 @@ void View::show_region(uint64_t start, uint64_t end, bool keep) if (keep) { set_all_update(true); update(); - } else if (_session.get_map_zoom() == 0) { - const double ideal_scale = (end-start) * 2.0 / _session.cur_snap_samplerate() / get_view_width(); + } else if (_session->get_map_zoom() == 0) { + const double ideal_scale = (end-start) * 2.0 / _session->cur_snap_samplerate() / get_view_width(); const double new_scale = max(min(ideal_scale, _maxscale), _minscale); - const double new_off = (start + end) * 0.5 / (_session.cur_snap_samplerate() * new_scale) - (get_view_width() / 2); + const double new_off = (start + end) * 0.5 / (_session->cur_snap_samplerate() * new_scale) - (get_view_width() / 2); set_scale_offset(new_scale, new_off); } else { const double new_scale = scale(); - const double new_off = (start + end) * 0.5 / (_session.cur_snap_samplerate() * new_scale) - (get_view_width() / 2); + const double new_off = (start + end) * 0.5 / (_session->cur_snap_samplerate() * new_scale) - (get_view_width() / 2); set_scale_offset(new_scale, new_off); } } @@ -1214,7 +1219,7 @@ void View::clear() { show_trig_cursor(false); - if (_session.get_device()->dev_inst()->mode != DSO) { + if (_session->get_device()->dev_inst()->mode != DSO) { show_xcursors(false); } else { if (!get_xcursorList().empty()) @@ -1224,7 +1229,7 @@ void View::clear() void View::reconstruct() { - if (_session.get_device()->dev_inst()->mode == DSO) + if (_session->get_device()->dev_inst()->mode == DSO) _viewbottom->setFixedHeight(DsoStatusHeight); else _viewbottom->setFixedHeight(StatusHeight); @@ -1240,7 +1245,7 @@ void View::set_capture_status() { bool triggered; int progress; - if (_session.get_capture_status(triggered, progress)) { + if (_session->get_capture_status(triggered, progress)) { _viewbottom->set_capture_status(triggered, progress); _viewbottom->update(); } diff --git a/DSView/pv/view/view.h b/DSView/pv/view/view.h index e059d461..306653d2 100755 --- a/DSView/pv/view/view.h +++ b/DSView/pv/view/view.h @@ -105,7 +105,7 @@ public: static const QColor LightRed; public: - explicit View(SigSession &session, pv::toolbars::SamplingBar *sampling_bar, QWidget *parent = 0); + explicit View(SigSession *session, pv::toolbars::SamplingBar *sampling_bar, QWidget *parent = 0); SigSession& session(); @@ -260,7 +260,7 @@ signals: void auto_trig(int index); -private: +private: void get_scroll_layout(int64_t &length, int64_t &offset) const; void update_scroll(); @@ -337,7 +337,7 @@ private slots: private: - SigSession &_session; + SigSession *_session; pv::toolbars::SamplingBar *_sampling_bar; QWidget *_viewcenter; diff --git a/DSView/pv/view/viewstatus.cpp b/DSView/pv/view/viewstatus.cpp index 83db6d83..739df933 100755 --- a/DSView/pv/view/viewstatus.cpp +++ b/DSView/pv/view/viewstatus.cpp @@ -40,7 +40,7 @@ using namespace std; namespace pv { namespace view { -ViewStatus::ViewStatus(SigSession &session, View &parent) : +ViewStatus::ViewStatus(SigSession *session, View &parent) : QWidget(&parent), _session(session), _view(parent), @@ -57,7 +57,7 @@ void ViewStatus::paintEvent(QPaintEvent *) style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); QColor fore(QWidget::palette().color(QWidget::foregroundRole())); - if (_session.get_device()->dev_inst()->mode == LOGIC) { + if (_session->get_device()->dev_inst()->mode == LOGIC) { fore.setAlpha(View::ForeAlpha); p.setPen(fore); p.drawText(this->rect(), Qt::AlignLeft | Qt::AlignVCenter, _rle_depth); @@ -66,16 +66,16 @@ void ViewStatus::paintEvent(QPaintEvent *) p.setPen(Qt::NoPen); p.setBrush(View::Blue); p.drawRect(this->rect().left(), this->rect().bottom() - 3, - _session.get_repeat_hold() * this->rect().width() / 100, 3); + _session->get_repeat_hold() * this->rect().width() / 100, 3); p.setPen(View::Blue); p.drawText(this->rect(), Qt::AlignCenter | Qt::AlignVCenter, _capture_status); - } else if (_session.get_device()->dev_inst()->mode == DSO) { + } else if (_session->get_device()->dev_inst()->mode == DSO) { fore.setAlpha(View::BackAlpha); for(size_t i = 0; i < _mrects.size(); i++) { int sig_index = std::get<1>(_mrects[i]); boost::shared_ptr dsoSig = NULL; - const vector< boost::shared_ptr > sigs(_session.get_signals()); + const vector< boost::shared_ptr > sigs(_session->get_signals()); BOOST_FOREACH(const boost::shared_ptr s, sigs) { assert(s); if (!s->enabled()) @@ -133,7 +133,7 @@ void ViewStatus::reload() const int COLUMN = 5; const int ROW = 2; const int MARGIN = 3; - if (_session.get_device()->dev_inst()->mode == DSO) + if (_session->get_device()->dev_inst()->mode == DSO) { const double width = _view.get_view_width() * 1.0 / COLUMN; const int height = (this->height() - 2*MARGIN) / ROW; @@ -184,7 +184,7 @@ void ViewStatus::mousePressEvent(QMouseEvent *event) { assert(event); - if (_session.get_device()->dev_inst()->mode != DSO) + if (_session->get_device()->dev_inst()->mode != DSO) return; if (event->button() == Qt::LeftButton) { @@ -233,7 +233,7 @@ QJsonArray ViewStatus::get_session() void ViewStatus::load_session(QJsonArray measure_array) { - if (_session.get_device()->dev_inst()->mode != DSO || + if (_session->get_device()->dev_inst()->mode != DSO || measure_array.empty()) return; diff --git a/DSView/pv/view/viewstatus.h b/DSView/pv/view/viewstatus.h index c4a006eb..56cfaa43 100755 --- a/DSView/pv/view/viewstatus.h +++ b/DSView/pv/view/viewstatus.h @@ -47,7 +47,7 @@ class ViewStatus : public QWidget Q_OBJECT public: - ViewStatus(SigSession &session, View &parent); + ViewStatus(SigSession *session, View &parent); public: @@ -71,7 +71,7 @@ public slots: void set_capture_status(bool triggered, int progess); private: - SigSession &_session; + SigSession *_session; View &_view; int _hit_rect;