]> sigrok.org Git - pulseview.git/commitdiff
Moved DevInst::_sdi down into Device
authorJoel Holdsworth <redacted>
Sat, 22 Feb 2014 10:35:39 +0000 (10:35 +0000)
committerJoel Holdsworth <redacted>
Sat, 1 Mar 2014 11:02:11 +0000 (11:02 +0000)
pv/device/device.cpp
pv/device/device.h
pv/device/devinst.cpp
pv/device/devinst.h

index ca18fc13a73e2f63432832a9b536568d658f0437..be25b5cb1cd017abb7ae0dd46f55650aeeb31878 100644 (file)
@@ -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
index fe91a6cbcdb797b5f6da501ca802ad14239c8d64..2abacbc46b692d60df4f25eacfbe49c6dc99bb97 100644 (file)
@@ -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
index adbf8968595e80cc66441dcd48985fc18d25df5b..44c1a83154f1f5b046290353a0ddbc4beb36b2da 100644 (file)
 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<sr_probe*>(probe)->enabled = enable;
                        config_changed();
index 9098027eb84e0674da978a65c38e67df3485c36f..fb0b7dfbb89f1ce3d96366952f8198d3bac2fed3 100644 (file)
@@ -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;
 };