From: Joel Holdsworth Date: Sat, 22 Feb 2014 10:35:39 +0000 (+0000) Subject: Moved DevInst::_sdi down into Device X-Git-Tag: pulseview-0.2.0~53 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=29efe92a807a93572b44369d2703f572778ebb15;p=pulseview.git Moved DevInst::_sdi down into Device --- diff --git a/pv/device/device.cpp b/pv/device/device.cpp index ca18fc13..be25b5cb 100644 --- a/pv/device/device.cpp +++ b/pv/device/device.cpp @@ -31,8 +31,14 @@ namespace pv { namespace device { Device::Device(sr_dev_inst *sdi) : - DevInst(sdi) + _sdi(sdi) { + assert(_sdi); +} + +sr_dev_inst* Device::dev_inst() const +{ + return _sdi; } std::string Device::format_device_title() const diff --git a/pv/device/device.h b/pv/device/device.h index fe91a6cb..2abacbc4 100644 --- a/pv/device/device.h +++ b/pv/device/device.h @@ -31,7 +31,12 @@ class Device : public DevInst public: Device(sr_dev_inst *dev_inst); + sr_dev_inst* dev_inst() const; + std::string format_device_title() const; + +private: + sr_dev_inst *const _sdi; }; } // device diff --git a/pv/device/devinst.cpp b/pv/device/devinst.cpp index adbf8968..44c1a831 100644 --- a/pv/device/devinst.cpp +++ b/pv/device/devinst.cpp @@ -31,16 +31,9 @@ namespace pv { namespace device { -DevInst::DevInst(sr_dev_inst *sdi) : - _sdi(sdi), +DevInst::DevInst() : _owner(NULL) { - assert(_sdi); -} - -sr_dev_inst* DevInst::dev_inst() const -{ - return _sdi; } void DevInst::use(SigSession *owner) @@ -48,7 +41,7 @@ void DevInst::use(SigSession *owner) assert(owner); assert(!_owner); _owner = owner; - sr_dev_open(_sdi); + sr_dev_open(dev_inst()); } void DevInst::release() @@ -56,7 +49,7 @@ void DevInst::release() if (_owner) { _owner->release_device(this); _owner = NULL; - sr_dev_close(_sdi); + sr_dev_close(dev_inst()); } } @@ -68,14 +61,18 @@ SigSession* DevInst::owner() const 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) + sr_dev_inst *const sdi = dev_inst(); + assert(sdi); + 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) { + sr_dev_inst *const sdi = dev_inst(); + assert(sdi); + if(sr_config_set(sdi, group, key, data) == SR_OK) { config_changed(); return true; } @@ -85,14 +82,18 @@ bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data) 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) + sr_dev_inst *const sdi = dev_inst(); + assert(sdi); + 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) + sr_dev_inst *const sdi = dev_inst(); + assert(sdi); + for (const GSList *p = sdi->probes; p; p = p->next) if (probe == p->data) { const_cast(probe)->enabled = enable; config_changed(); diff --git a/pv/device/devinst.h b/pv/device/devinst.h index 9098027e..fb0b7dfb 100644 --- a/pv/device/devinst.h +++ b/pv/device/devinst.h @@ -46,10 +46,10 @@ class DevInst : public QObject Q_OBJECT protected: - DevInst(sr_dev_inst *sdi); + DevInst(); public: - sr_dev_inst* dev_inst() const; + virtual sr_dev_inst* dev_inst() const = 0; void use(SigSession *owner); @@ -79,7 +79,6 @@ signals: void config_changed(); protected: - sr_dev_inst *const _sdi; SigSession *_owner; };