]> sigrok.org Git - pulseview.git/blobdiff - pv/device/devinst.cpp
Moved DeviceManager::use_device and release_device into DevInst
[pulseview.git] / pv / device / devinst.cpp
index a5f96808e55d14161050b5d3e966ca0e847b3c62..adbf8968595e80cc66441dcd48985fc18d25df5b 100644 (file)
@@ -19,7 +19,6 @@
  */
 
 #include <cassert>
-#include <sstream>
 
 #include <QDebug>
 
 
 #include "devinst.h"
 
-using std::ostringstream;
-using std::string;
+#include <pv/sigsession.h>
 
 namespace pv {
 namespace device {
 
 DevInst::DevInst(sr_dev_inst *sdi) :
-       _sdi(sdi)
+       _sdi(sdi),
+       _owner(NULL)
 {
        assert(_sdi);
 }
@@ -44,29 +43,26 @@ sr_dev_inst* DevInst::dev_inst() const
        return _sdi;
 }
 
-string DevInst::format_device_title() const
+void DevInst::use(SigSession *owner)
 {
-       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 << ' ';
-       }
+       assert(owner);
+       assert(!_owner);
+       _owner = owner;
+       sr_dev_open(_sdi);
+}
 
-       if (_sdi->model && _sdi->model[0]) {
-               s << _sdi->model;
-               if (_sdi->version && _sdi->version[0])
-                       s << ' ';
+void DevInst::release()
+{
+       if (_owner) {
+               _owner->release_device(this);
+               _owner = NULL;
+               sr_dev_close(_sdi);
        }
+}
 
-       if (_sdi->version && _sdi->version[0])
-               s << _sdi->version;
-
-       return s.str();
+SigSession* DevInst::owner() const
+{
+       return _owner;
 }
 
 GVariant* DevInst::get_config(const sr_probe_group *group, int key)