From: Joel Holdsworth Date: Wed, 19 Feb 2014 22:18:01 +0000 (+0000) Subject: Moved DevInst into the pv::device namespace X-Git-Tag: pulseview-0.2.0~57 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=945745012eb57cefa1ef457daf48cfffa99f9ec2 Moved DevInst into the pv::device namespace --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d959a9f3..aaed2d61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,7 +118,6 @@ configure_file ( set(pulseview_SOURCES main.cpp pv/devicemanager.cpp - pv/devinst.cpp pv/mainwindow.cpp pv/sigsession.cpp pv/storesession.cpp @@ -128,6 +127,7 @@ set(pulseview_SOURCES pv/data/logicsnapshot.cpp pv/data/signaldata.cpp pv/data/snapshot.cpp + pv/device/devinst.cpp pv/dialogs/about.cpp pv/dialogs/connect.cpp pv/dialogs/storeprogress.cpp @@ -166,10 +166,10 @@ set(pulseview_SOURCES # This list includes only QObject derived class headers. set(pulseview_HEADERS - pv/devinst.h pv/mainwindow.h pv/sigsession.h pv/storesession.h + pv/device/devinst.h pv/dialogs/about.h pv/dialogs/connect.h pv/dialogs/storeprogress.h diff --git a/pv/device/devinst.cpp b/pv/device/devinst.cpp new file mode 100644 index 00000000..a5f96808 --- /dev/null +++ b/pv/device/devinst.cpp @@ -0,0 +1,124 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * 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 +#include + +#include + +#include + +#include "devinst.h" + +using std::ostringstream; +using std::string; + +namespace pv { +namespace device { + +DevInst::DevInst(sr_dev_inst *sdi) : + _sdi(sdi) +{ + assert(_sdi); +} + +sr_dev_inst* DevInst::dev_inst() const +{ + return _sdi; +} + +string DevInst::format_device_title() const +{ + ostringstream s; + + assert(_sdi); + + if (_sdi->vendor && _sdi->vendor[0]) { + s << _sdi->vendor; + if ((_sdi->model && _sdi->model[0]) || + (_sdi->version && _sdi->version[0])) + s << ' '; + } + + if (_sdi->model && _sdi->model[0]) { + s << _sdi->model; + if (_sdi->version && _sdi->version[0]) + s << ' '; + } + + if (_sdi->version && _sdi->version[0]) + s << _sdi->version; + + return s.str(); +} + +GVariant* DevInst::get_config(const sr_probe_group *group, int key) +{ + GVariant *data = NULL; + if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK) + return NULL; + return data; +} + +bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data) +{ + if(sr_config_set(_sdi, group, key, data) == SR_OK) { + config_changed(); + return true; + } + return false; +} + +GVariant* DevInst::list_config(const sr_probe_group *group, int key) +{ + GVariant *data = NULL; + if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK) + return NULL; + return data; +} + +void DevInst::enable_probe(const sr_probe *probe, bool enable) +{ + for (const GSList *p = _sdi->probes; p; p = p->next) + if (probe == p->data) { + const_cast(probe)->enabled = enable; + config_changed(); + return; + } + + // Probe was not found in the device + assert(0); +} + +uint64_t DevInst::get_sample_limit() +{ + uint64_t sample_limit; + GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES); + if (gvar != NULL) { + sample_limit = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } else { + sample_limit = 0U; + } + return sample_limit; +} + +} // device +} // pv diff --git a/pv/device/devinst.h b/pv/device/devinst.h new file mode 100644 index 00000000..073813f2 --- /dev/null +++ b/pv/device/devinst.h @@ -0,0 +1,78 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * 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 + */ + +#ifndef PULSEVIEW_PV_DEVICE_DEVINST_H +#define PULSEVIEW_PV_DEVICE_DEVINST_H + +#include + +#include + +#include + +#include + +#include + +struct sr_dev_inst; +struct sr_probe; +struct sr_probe_group; + +namespace pv { +namespace device { + +class DevInst : public QObject +{ + Q_OBJECT + +public: + DevInst(sr_dev_inst *sdi); + + sr_dev_inst* dev_inst() const; + + std::string format_device_title() const; + + GVariant* get_config(const sr_probe_group *group, int key); + + bool set_config(const sr_probe_group *group, int key, GVariant *data); + + GVariant* list_config(const sr_probe_group *group, int key); + + void enable_probe(const sr_probe *probe, bool enable = true); + + /** + * @brief Gets the sample limit from the driver. + * + * @return The returned sample limit from the driver, or 0 if the + * sample limit could not be read. + */ + uint64_t get_sample_limit(); + +signals: + void config_changed(); + +private: + sr_dev_inst *const _sdi; +}; + +} // device +} // pv + +#endif // PULSEVIEW_PV_DEVICE_DEVINST_H diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 39c311c5..11a5fe3c 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -19,7 +19,7 @@ */ #include "devicemanager.h" -#include "devinst.h" +#include "device/devinst.h" #include "sigsession.h" #include @@ -49,12 +49,13 @@ DeviceManager::~DeviceManager() release_devices(); } -const list< shared_ptr >& DeviceManager::devices() const +const list< shared_ptr >& DeviceManager::devices() const { return _devices; } -void DeviceManager::use_device(shared_ptr dev_inst, SigSession *owner) +void DeviceManager::use_device(shared_ptr dev_inst, + SigSession *owner) { assert(dev_inst); assert(owner); @@ -64,29 +65,29 @@ void DeviceManager::use_device(shared_ptr dev_inst, SigSession *owner) sr_dev_open(dev_inst->dev_inst()); } -void DeviceManager::release_device(shared_ptr dev_inst) +void DeviceManager::release_device(shared_ptr dev_inst) { assert(dev_inst); // Notify the owner, and remove the device from the used device list - map< shared_ptr, pv::SigSession*>::const_iterator iter = - _used_devices.find(dev_inst); + map< shared_ptr, pv::SigSession*>::const_iterator + iter = _used_devices.find(dev_inst); assert(iter != _used_devices.end()); (*iter).second->release_device(dev_inst); _used_devices.erase(dev_inst); } -list< shared_ptr > DeviceManager::driver_scan( +list< shared_ptr > DeviceManager::driver_scan( struct sr_dev_driver *const driver, GSList *const drvopts) { - list< shared_ptr > driver_devices; + list< shared_ptr > 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(); + list< shared_ptr >::iterator i = _devices.begin(); while (i != _devices.end()) { if ((*i)->dev_inst()->driver == driver) i = _devices.erase(i); @@ -100,8 +101,8 @@ list< shared_ptr > DeviceManager::driver_scan( // Do the scan GSList *const devices = sr_driver_scan(driver, drvopts); for (GSList *l = devices; l; l = l->next) - driver_devices.push_back(shared_ptr( - new DevInst((sr_dev_inst*)l->data))); + driver_devices.push_back(shared_ptr( + new device::DevInst((sr_dev_inst*)l->data))); g_slist_free(devices); driver_devices.sort(compare_devices); @@ -129,7 +130,7 @@ void DeviceManager::init_drivers() void DeviceManager::release_devices() { // Release all the used devices - for (map, SigSession*>::iterator i = + for (map, SigSession*>::iterator i = _used_devices.begin(); i != _used_devices.end(); i++) release_device((*i).first); @@ -152,7 +153,7 @@ void DeviceManager::scan_all_drivers() void DeviceManager::release_driver(struct sr_dev_driver *const driver) { assert(driver); - for (map, SigSession*>::iterator i = + for (map, SigSession*>::iterator i = _used_devices.begin(); i != _used_devices.end(); i++) if((*i).first->dev_inst()->driver == driver) { @@ -170,8 +171,8 @@ void DeviceManager::release_driver(struct sr_dev_driver *const driver) sr_dev_clear(driver); } -bool DeviceManager::compare_devices(shared_ptr a, - shared_ptr b) +bool DeviceManager::compare_devices(shared_ptr a, + shared_ptr b) { assert(a); assert(b); diff --git a/pv/devicemanager.h b/pv/devicemanager.h index 891ba3d2..3ed74e07 100644 --- a/pv/devicemanager.h +++ b/pv/devicemanager.h @@ -34,9 +34,12 @@ struct sr_dev_driver; namespace pv { -class DevInst; class SigSession; +namespace device { +class DevInst; +} + class DeviceManager { public: @@ -44,14 +47,15 @@ public: ~DeviceManager(); - const std::list< boost::shared_ptr >& devices() const; + const std::list< boost::shared_ptr >& + devices() const; - void use_device(boost::shared_ptr dev_inst, + void use_device(boost::shared_ptr dev_inst, SigSession *owner); - void release_device(boost::shared_ptr dev_inst); + void release_device(boost::shared_ptr dev_inst); - std::list< boost::shared_ptr > driver_scan( + std::list< boost::shared_ptr > driver_scan( struct sr_dev_driver *const driver, GSList *const drvopts = NULL); @@ -64,13 +68,13 @@ 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(boost::shared_ptr a, + boost::shared_ptr b); private: struct sr_context *const _sr_ctx; - std::list< boost::shared_ptr > _devices; - std::map< boost::shared_ptr, pv::SigSession*> + std::list< boost::shared_ptr > _devices; + std::map< boost::shared_ptr, pv::SigSession*> _used_devices; }; diff --git a/pv/devinst.cpp b/pv/devinst.cpp deleted file mode 100644 index b28fce08..00000000 --- a/pv/devinst.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2014 Joel Holdsworth - * - * 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 -#include - -#include - -#include - -#include "devinst.h" - -using std::ostringstream; -using std::string; - -namespace pv { - -DevInst::DevInst(sr_dev_inst *sdi) : - _sdi(sdi) -{ - assert(_sdi); -} - -sr_dev_inst* DevInst::dev_inst() const -{ - return _sdi; -} - -string DevInst::format_device_title() const -{ - ostringstream s; - - assert(_sdi); - - if (_sdi->vendor && _sdi->vendor[0]) { - s << _sdi->vendor; - if ((_sdi->model && _sdi->model[0]) || - (_sdi->version && _sdi->version[0])) - s << ' '; - } - - if (_sdi->model && _sdi->model[0]) { - s << _sdi->model; - if (_sdi->version && _sdi->version[0]) - s << ' '; - } - - if (_sdi->version && _sdi->version[0]) - s << _sdi->version; - - return s.str(); -} - -GVariant* DevInst::get_config(const sr_probe_group *group, int key) -{ - GVariant *data = NULL; - if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK) - return NULL; - return data; -} - -bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data) -{ - if(sr_config_set(_sdi, group, key, data) == SR_OK) { - config_changed(); - return true; - } - return false; -} - -GVariant* DevInst::list_config(const sr_probe_group *group, int key) -{ - GVariant *data = NULL; - if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK) - return NULL; - return data; -} - -void DevInst::enable_probe(const sr_probe *probe, bool enable) -{ - for (const GSList *p = _sdi->probes; p; p = p->next) - if (probe == p->data) { - const_cast(probe)->enabled = enable; - config_changed(); - return; - } - - // Probe was not found in the device - assert(0); -} - -uint64_t DevInst::get_sample_limit() -{ - uint64_t sample_limit; - GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES); - if (gvar != NULL) { - sample_limit = g_variant_get_uint64(gvar); - g_variant_unref(gvar); - } else { - sample_limit = 0U; - } - return sample_limit; -} - -} // pv diff --git a/pv/devinst.h b/pv/devinst.h deleted file mode 100644 index e57a4e44..00000000 --- a/pv/devinst.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the PulseView project. - * - * Copyright (C) 2014 Joel Holdsworth - * - * 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 - */ - -#ifndef PULSEVIEW_PV_DEVINST_H -#define PULSEVIEW_PV_DEVINST_H - -#include - -#include - -#include - -#include - -#include - -struct sr_dev_inst; -struct sr_probe; -struct sr_probe_group; - -namespace pv { - -class DevInst : public QObject -{ - Q_OBJECT - -public: - DevInst(sr_dev_inst *sdi); - - sr_dev_inst* dev_inst() const; - - std::string format_device_title() const; - - GVariant* get_config(const sr_probe_group *group, int key); - - bool set_config(const sr_probe_group *group, int key, GVariant *data); - - GVariant* list_config(const sr_probe_group *group, int key); - - void enable_probe(const sr_probe *probe, bool enable = true); - - /** - * @brief Gets the sample limit from the driver. - * - * @return The returned sample limit from the driver, or 0 if the - * sample limit could not be read. - */ - uint64_t get_sample_limit(); - -signals: - void config_changed(); - -private: - sr_dev_inst *const _sdi; -}; - -} // pv - -#endif // PULSEVIEW_PV_DEVINST_H diff --git a/pv/dialogs/connect.cpp b/pv/dialogs/connect.cpp index 11cf0e7b..7b31942d 100644 --- a/pv/dialogs/connect.cpp +++ b/pv/dialogs/connect.cpp @@ -25,7 +25,7 @@ #include "connect.h" #include "pv/devicemanager.h" -#include "pv/devinst.h" +#include "pv/device/devinst.h" extern "C" { /* __STDC_FORMAT_MACROS is required for PRIu64 and friends (in C++). */ @@ -82,17 +82,17 @@ Connect::Connect(QWidget *parent, pv::DeviceManager &device_manager) : _layout.addWidget(&_button_box); } -shared_ptr Connect::get_selected_device() const +shared_ptr Connect::get_selected_device() const { const QListWidgetItem *const item = _device_list.currentItem(); if (!item) - return shared_ptr(); + return shared_ptr(); const sr_dev_inst *const sdi = (sr_dev_inst*)item->data( Qt::UserRole).value(); assert(sdi); - std::map >:: + std::map >:: const_iterator iter = _device_map.find(sdi); assert(iter != _device_map.end()); @@ -170,12 +170,12 @@ void Connect::scan_pressed() drvopts = g_slist_append(drvopts, src); } - const list< shared_ptr > devices = _device_manager.driver_scan( - driver, drvopts); + const list< shared_ptr > devices = + _device_manager.driver_scan(driver, drvopts); g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts); - BOOST_FOREACH(shared_ptr dev_inst, devices) + BOOST_FOREACH(shared_ptr dev_inst, devices) { assert(dev_inst); const sr_dev_inst *const sdi = dev_inst->dev_inst(); diff --git a/pv/dialogs/connect.h b/pv/dialogs/connect.h index 0f272cae..5a8b1cd0 100644 --- a/pv/dialogs/connect.h +++ b/pv/dialogs/connect.h @@ -38,7 +38,10 @@ struct sr_dev_inst; namespace pv { class DeviceManager; + +namespace device { class DevInst; +} namespace dialogs { @@ -49,7 +52,7 @@ class Connect : public QDialog public: Connect(QWidget *parent, pv::DeviceManager &device_manager); - boost::shared_ptr get_selected_device() const; + boost::shared_ptr get_selected_device() const; private: void populate_drivers(); @@ -80,7 +83,7 @@ private: QPushButton _scan_button; QListWidget _device_list; - std::map > + std::map > _device_map; QDialogButtonBox _button_box; diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 0b2805b1..f72d1b70 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -39,7 +39,7 @@ #include "mainwindow.h" #include "devicemanager.h" -#include "devinst.h" +#include "device/devinst.h" #include "dialogs/about.h" #include "dialogs/connect.h" #include "dialogs/storeprogress.h" @@ -284,11 +284,13 @@ void MainWindow::session_error( Q_ARG(QString, info_text)); } -void MainWindow::update_device_list(shared_ptr selected_device) +void MainWindow::update_device_list( + shared_ptr selected_device) { assert(_sampling_bar); - const list< shared_ptr > &devices = _device_manager.devices(); + const list< shared_ptr > &devices = + _device_manager.devices(); _sampling_bar->set_device_list(devices); if (!selected_device && !devices.empty()) { @@ -296,7 +298,7 @@ void MainWindow::update_device_list(shared_ptr selected_device) selected_device = devices.front(); // Try and find the demo device and select that by default - BOOST_FOREACH (shared_ptr dev_inst, devices) + BOOST_FOREACH (shared_ptr dev_inst, devices) if (strcmp(dev_inst->dev_inst()->driver->name, "demo") == 0) { selected_device = dev_inst; @@ -368,7 +370,7 @@ void MainWindow::on_actionConnect_triggered() // If the user selected a device, select it in the device list. Select the // current device otherwise. - shared_ptr dev_inst = dlg.exec() ? + shared_ptr dev_inst = dlg.exec() ? dlg.get_selected_device() : _session.get_device(); update_device_list(dev_inst); diff --git a/pv/mainwindow.h b/pv/mainwindow.h index 6f3c8d56..1acaf072 100644 --- a/pv/mainwindow.h +++ b/pv/mainwindow.h @@ -36,7 +36,10 @@ class QVBoxLayout; namespace pv { class DeviceManager; + +namespace device { class DevInst; +} namespace toolbars { class ContextBar; @@ -72,8 +75,8 @@ private: * first device in the device list should be selected. */ void update_device_list( - boost::shared_ptr selected_device = - boost::shared_ptr()); + boost::shared_ptr selected_device = + boost::shared_ptr()); private slots: void load_file(QString file_name); diff --git a/pv/popups/deviceoptions.cpp b/pv/popups/deviceoptions.cpp index 7e1be20d..13055fc0 100644 --- a/pv/popups/deviceoptions.cpp +++ b/pv/popups/deviceoptions.cpp @@ -32,7 +32,8 @@ using boost::shared_ptr; namespace pv { namespace popups { -DeviceOptions::DeviceOptions(shared_ptr dev_inst, QWidget *parent) : +DeviceOptions::DeviceOptions(shared_ptr dev_inst, + QWidget *parent) : Popup(parent), _dev_inst(dev_inst), _layout(this), diff --git a/pv/popups/deviceoptions.h b/pv/popups/deviceoptions.h index 745ed994..945959b2 100644 --- a/pv/popups/deviceoptions.h +++ b/pv/popups/deviceoptions.h @@ -35,12 +35,13 @@ class DeviceOptions : public pv::widgets::Popup Q_OBJECT public: - DeviceOptions(boost::shared_ptr dev_inst, QWidget *parent); + DeviceOptions(boost::shared_ptr dev_inst, + QWidget *parent); pv::prop::binding::DeviceOptions& binding(); private: - boost::shared_ptr _dev_inst; + boost::shared_ptr _dev_inst; QVBoxLayout _layout; diff --git a/pv/popups/probes.cpp b/pv/popups/probes.cpp index b19f8967..13380c2d 100644 --- a/pv/popups/probes.cpp +++ b/pv/popups/probes.cpp @@ -29,7 +29,7 @@ #include "probes.h" -#include +#include #include #include #include @@ -57,7 +57,7 @@ Probes::Probes(SigSession &session, QWidget *parent) : // Create the layout setLayout(&_layout); - shared_ptr dev_inst = _session.get_device(); + shared_ptr dev_inst = _session.get_device(); assert(dev_inst); const sr_dev_inst *const sdi = dev_inst->dev_inst(); assert(sdi); diff --git a/pv/prop/binding/deviceoptions.cpp b/pv/prop/binding/deviceoptions.cpp index 01648692..ea8f4b42 100644 --- a/pv/prop/binding/deviceoptions.cpp +++ b/pv/prop/binding/deviceoptions.cpp @@ -24,7 +24,7 @@ #include "deviceoptions.h" -#include +#include #include #include #include @@ -45,7 +45,7 @@ namespace pv { namespace prop { namespace binding { -DeviceOptions::DeviceOptions(shared_ptr dev_inst, +DeviceOptions::DeviceOptions(shared_ptr dev_inst, const sr_probe_group *group) : _dev_inst(dev_inst), _group(group) @@ -122,8 +122,9 @@ void DeviceOptions::bind_bool(const QString &name, int key) { assert(_dev_inst); _properties.push_back(shared_ptr(new Bool(name, - bind(&DevInst::get_config, _dev_inst, _group, key), - bind(&DevInst::set_config, _dev_inst, _group, key, _1)))); + bind(&device::DevInst::get_config, _dev_inst, _group, key), + bind(&device::DevInst::set_config, _dev_inst, + _group, key, _1)))); } void DeviceOptions::bind_enum(const QString &name, int key, @@ -141,8 +142,9 @@ void DeviceOptions::bind_enum(const QString &name, int key, values.push_back(make_pair(gvar, printer(gvar))); _properties.push_back(shared_ptr(new Enum(name, values, - bind(&DevInst::get_config, _dev_inst, _group, key), - bind(&DevInst::set_config, _dev_inst, _group, key, _1)))); + bind(&device::DevInst::get_config, _dev_inst, _group, key), + bind(&device::DevInst::set_config, _dev_inst, + _group, key, _1)))); } void DeviceOptions::bind_int(const QString &name, int key, QString suffix, @@ -151,8 +153,8 @@ void DeviceOptions::bind_int(const QString &name, int key, QString suffix, assert(_dev_inst); _properties.push_back(shared_ptr(new Int(name, suffix, range, - bind(&DevInst::get_config, _dev_inst, _group, key), - bind(&DevInst::set_config, _dev_inst, _group, key, _1)))); + bind(&device::DevInst::get_config, _dev_inst, _group, key), + bind(&device::DevInst::set_config, _dev_inst, _group, key, _1)))); } QString DeviceOptions::print_gvariant(GVariant *const gvar) diff --git a/pv/prop/binding/deviceoptions.h b/pv/prop/binding/deviceoptions.h index 8814dc34..4a6eff2e 100644 --- a/pv/prop/binding/deviceoptions.h +++ b/pv/prop/binding/deviceoptions.h @@ -35,7 +35,9 @@ struct sr_probe_group; namespace pv { +namespace device { class DevInst; +} namespace prop { namespace binding { @@ -43,7 +45,7 @@ namespace binding { class DeviceOptions : public Binding { public: - DeviceOptions(boost::shared_ptr dev_inst, + DeviceOptions(boost::shared_ptr dev_inst, const sr_probe_group *group = NULL); private: @@ -61,7 +63,7 @@ private: static QString print_voltage_threshold(GVariant *const gvar); protected: - boost::shared_ptr _dev_inst; + boost::shared_ptr _dev_inst; const sr_probe_group *const _group; }; diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index b5387877..622bf8d2 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -25,7 +25,7 @@ #include "sigsession.h" #include "devicemanager.h" -#include "devinst.h" +#include "device/devinst.h" #include "data/analog.h" #include "data/analogsnapshot.h" @@ -85,12 +85,12 @@ SigSession::~SigSession() _session = NULL; } -shared_ptr SigSession::get_device() const +shared_ptr SigSession::get_device() const { return _dev_inst; } -void SigSession::set_device(shared_ptr dev_inst) +void SigSession::set_device(shared_ptr dev_inst) { // Ensure we are not capturing before setting the device stop_capture(); @@ -103,12 +103,12 @@ void SigSession::set_device(shared_ptr dev_inst) update_signals(dev_inst); } -void SigSession::release_device(shared_ptr dev_inst) +void SigSession::release_device(shared_ptr dev_inst) { (void)dev_inst; assert(_capture_state == Stopped); - _dev_inst = shared_ptr(); + _dev_inst = shared_ptr(); } void SigSession::load_file(const string &name, @@ -126,8 +126,8 @@ void SigSession::load_file(const string &name, return; } - shared_ptr dev_inst( - new DevInst((sr_dev_inst*)devlist->data)); + shared_ptr dev_inst( + new device::DevInst((sr_dev_inst*)devlist->data)); g_slist_free(devlist); _decode_traces.clear(); @@ -146,7 +146,8 @@ void SigSession::load_file(const string &name, return; _decode_traces.clear(); - update_signals(shared_ptr(new DevInst(in->sdi))); + update_signals(shared_ptr( + new device::DevInst(in->sdi))); read_sample_rate(in->sdi); _sampling_thread = boost::thread( @@ -386,7 +387,7 @@ sr_input* SigSession::load_input_file_format(const string &filename, return in; } -void SigSession::update_signals(shared_ptr dev_inst) +void SigSession::update_signals(shared_ptr dev_inst) { assert(dev_inst); assert(_capture_state == Stopped); @@ -568,7 +569,7 @@ void SigSession::load_input_thread_proc(const string name, delete in; } -void SigSession::sample_thread_proc(shared_ptr dev_inst, +void SigSession::sample_thread_proc(shared_ptr dev_inst, function error_handler) { assert(dev_inst); diff --git a/pv/sigsession.h b/pv/sigsession.h index a9a7ce23..6b2e7599 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -41,7 +41,6 @@ struct srd_probe; namespace pv { class DeviceManager; -class DevInst; namespace data { class Analog; @@ -51,6 +50,10 @@ class LogicSnapshot; class SignalData; } +namespace device { +class DevInst; +} + namespace view { class DecodeTrace; class LogicSignal; @@ -73,14 +76,14 @@ public: ~SigSession(); - boost::shared_ptr get_device() const; + boost::shared_ptr 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(boost::shared_ptr dev_inst); - void release_device(boost::shared_ptr dev_inst); + void release_device(boost::shared_ptr dev_inst); void load_file(const std::string &name, boost::function error_handler); @@ -108,7 +111,7 @@ public: private: void set_capture_state(capture_state state); - void update_signals(boost::shared_ptr dev_inst); + void update_signals(boost::shared_ptr dev_inst); bool is_trigger_enabled() const; @@ -139,7 +142,7 @@ private: void load_input_thread_proc(const std::string name, sr_input *in, boost::function error_handler); - void sample_thread_proc(boost::shared_ptr dev_inst, + void sample_thread_proc(boost::shared_ptr dev_inst, boost::function error_handler); void feed_in_header(const sr_dev_inst *sdi); @@ -163,7 +166,7 @@ private: /** * The device instance that will be used in the next capture session. */ - boost::shared_ptr _dev_inst; + boost::shared_ptr _dev_inst; std::vector< boost::shared_ptr > _decode_traces; diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index 27af7c7b..f58f4fc3 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -30,7 +30,7 @@ #include "samplingbar.h" #include -#include +#include #include #include @@ -96,14 +96,14 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) : } void SamplingBar::set_device_list( - const std::list< shared_ptr > &devices) + const std::list< shared_ptr > &devices) { _updating_device_selector = true; _device_selector.clear(); _device_selector_map.clear(); - BOOST_FOREACH (shared_ptr dev_inst, devices) { + BOOST_FOREACH (shared_ptr dev_inst, devices) { assert(dev_inst); const string title = dev_inst->format_device_title(); const sr_dev_inst *sdi = dev_inst->dev_inst(); @@ -119,26 +119,26 @@ void SamplingBar::set_device_list( on_device_selected(); } -shared_ptr SamplingBar::get_selected_device() const +shared_ptr SamplingBar::get_selected_device() const { const int index = _device_selector.currentIndex(); if (index < 0) - return shared_ptr(); + return shared_ptr(); const sr_dev_inst *const sdi = (const sr_dev_inst*)_device_selector.itemData( index).value(); assert(sdi); - map >:: + map >:: const_iterator iter = _device_selector_map.find(sdi); if (iter == _device_selector_map.end()) - return shared_ptr(); + return shared_ptr(); - return shared_ptr((*iter).second); + return shared_ptr((*iter).second); } -void SamplingBar::set_selected_device(boost::shared_ptr dev_inst) +void SamplingBar::set_selected_device(shared_ptr dev_inst) { assert(dev_inst); @@ -167,7 +167,7 @@ void SamplingBar::update_sample_rate_selector() if (_updating_sample_rate) return; - const shared_ptr dev_inst = get_selected_device(); + const shared_ptr dev_inst = get_selected_device(); if (!dev_inst) return; @@ -231,7 +231,7 @@ void SamplingBar::update_sample_rate_selector_value() if (_updating_sample_rate) return; - const shared_ptr dev_inst = get_selected_device(); + const shared_ptr dev_inst = get_selected_device(); if (!dev_inst) return; @@ -255,7 +255,7 @@ void SamplingBar::update_sample_count_selector() if (_updating_sample_count) return; - const shared_ptr dev_inst = get_selected_device(); + const shared_ptr dev_inst = get_selected_device(); if (!dev_inst) return; @@ -307,7 +307,7 @@ void SamplingBar::commit_sample_count() if (_updating_sample_count) return; - const shared_ptr dev_inst = get_selected_device(); + const shared_ptr dev_inst = get_selected_device(); if (!dev_inst) return; @@ -331,7 +331,7 @@ void SamplingBar::commit_sample_rate() if (_updating_sample_rate) return; - const shared_ptr dev_inst = get_selected_device(); + const shared_ptr dev_inst = get_selected_device(); if (!dev_inst) return; @@ -359,7 +359,7 @@ void SamplingBar::on_device_selected() if (_updating_device_selector) return; - const shared_ptr dev_inst = get_selected_device(); + const shared_ptr dev_inst = get_selected_device(); if (!dev_inst) return; diff --git a/pv/toolbars/samplingbar.h b/pv/toolbars/samplingbar.h index 454d6079..db4e856e 100644 --- a/pv/toolbars/samplingbar.h +++ b/pv/toolbars/samplingbar.h @@ -41,9 +41,12 @@ class QAction; namespace pv { -class DevInst; class SigSession; +namespace device { +class DevInst; +} + namespace toolbars { class SamplingBar : public QToolBar @@ -59,10 +62,12 @@ public: SamplingBar(SigSession &session, QWidget *parent); void set_device_list( - const std::list< boost::shared_ptr > &devices); + const std::list< boost::shared_ptr > + &devices); - boost::shared_ptr get_selected_device() const; - void set_selected_device(boost::shared_ptr dev_inst); + boost::shared_ptr get_selected_device() const; + void set_selected_device( + boost::shared_ptr dev_inst); void set_capture_state(pv::SigSession::capture_state state); @@ -88,7 +93,7 @@ private: SigSession &_session; QComboBox _device_selector; - std::map > + std::map > _device_selector_map; bool _updating_device_selector; diff --git a/pv/view/analogsignal.cpp b/pv/view/analogsignal.cpp index a64cf70f..182e9abd 100644 --- a/pv/view/analogsignal.cpp +++ b/pv/view/analogsignal.cpp @@ -44,7 +44,7 @@ const QColor AnalogSignal::SignalColours[4] = { const float AnalogSignal::EnvelopeThreshold = 256.0f; -AnalogSignal::AnalogSignal(shared_ptr dev_inst, +AnalogSignal::AnalogSignal(shared_ptr dev_inst, const sr_probe *const probe, shared_ptr data) : Signal(dev_inst, probe), _data(data), diff --git a/pv/view/analogsignal.h b/pv/view/analogsignal.h index 3b6f7f4f..8101167d 100644 --- a/pv/view/analogsignal.h +++ b/pv/view/analogsignal.h @@ -42,7 +42,7 @@ private: static const float EnvelopeThreshold; public: - AnalogSignal(boost::shared_ptr dev_inst, + AnalogSignal(boost::shared_ptr dev_inst, const sr_probe *const probe, boost::shared_ptr data); diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index cc974f52..52cf4ac1 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -29,7 +29,7 @@ #include "view.h" #include -#include +#include #include #include #include @@ -63,7 +63,7 @@ const QColor LogicSignal::SignalColours[10] = { QColor(0xEE, 0xEE, 0xEC), // White }; -LogicSignal::LogicSignal(shared_ptr dev_inst, +LogicSignal::LogicSignal(shared_ptr dev_inst, const sr_probe *const probe, shared_ptr data) : Signal(dev_inst, probe), _data(data), diff --git a/pv/view/logicsignal.h b/pv/view/logicsignal.h index 17f6eb26..9b786574 100644 --- a/pv/view/logicsignal.h +++ b/pv/view/logicsignal.h @@ -49,7 +49,7 @@ private: static const QColor SignalColours[10]; public: - LogicSignal(boost::shared_ptr dev_inst, + LogicSignal(boost::shared_ptr dev_inst, const sr_probe *const probe, boost::shared_ptr data); diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 61f79a8c..aadaed78 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -32,7 +32,7 @@ #include "signal.h" #include "view.h" -#include +#include using boost::shared_ptr; @@ -56,7 +56,7 @@ const char *const ProbeNames[] = { "SCL" }; -Signal::Signal(shared_ptr dev_inst, +Signal::Signal(shared_ptr dev_inst, const sr_probe *const probe) : Trace(probe->name), _dev_inst(dev_inst), diff --git a/pv/view/signal.h b/pv/view/signal.h index 25b671f4..3123519b 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -34,12 +34,14 @@ struct sr_probe; namespace pv { -class DevInst; - namespace data { class SignalData; } +namespace device { +class DevInst; +} + namespace view { class Signal : public Trace @@ -47,7 +49,7 @@ class Signal : public Trace Q_OBJECT protected: - Signal(boost::shared_ptr dev_inst, + Signal(boost::shared_ptr dev_inst, const sr_probe *const probe); public: @@ -77,7 +79,7 @@ private slots: void on_disable(); protected: - boost::shared_ptr _dev_inst; + boost::shared_ptr _dev_inst; const sr_probe *const _probe; QComboBox *_name_widget; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ec833130..27d42f91 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,7 +47,6 @@ find_package(Qt4 REQUIRED) set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/devicemanager.cpp - ${PROJECT_SOURCE_DIR}/pv/devinst.cpp ${PROJECT_SOURCE_DIR}/pv/sigsession.cpp ${PROJECT_SOURCE_DIR}/pv/view/cursorpair.cpp ${PROJECT_SOURCE_DIR}/pv/data/analog.cpp @@ -58,6 +57,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/data/logicsnapshot.cpp ${PROJECT_SOURCE_DIR}/pv/data/snapshot.cpp ${PROJECT_SOURCE_DIR}/pv/data/signaldata.cpp + ${PROJECT_SOURCE_DIR}/pv/device/devinst.cpp ${PROJECT_SOURCE_DIR}/pv/prop/int.cpp ${PROJECT_SOURCE_DIR}/pv/prop/property.cpp ${PROJECT_SOURCE_DIR}/pv/prop/string.cpp @@ -88,7 +88,7 @@ set(pulseview_TEST_SOURCES # This list includes only QObject derived class headers. set(pulseview_TEST_HEADERS ${PROJECT_SOURCE_DIR}/pv/sigsession.h - ${PROJECT_SOURCE_DIR}/pv/devinst.h + ${PROJECT_SOURCE_DIR}/pv/device/devinst.h ${PROJECT_SOURCE_DIR}/pv/prop/int.h ${PROJECT_SOURCE_DIR}/pv/prop/property.h ${PROJECT_SOURCE_DIR}/pv/prop/string.h