Added pv::device::Device
authorJoel Holdsworth <joel@airwebreathe.org.uk>
Wed, 19 Feb 2014 22:50:07 +0000 (22:50 +0000)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Sat, 1 Mar 2014 11:02:11 +0000 (11:02 +0000)
CMakeLists.txt
pv/device/device.cpp [new file with mode: 0644]
pv/device/device.h [new file with mode: 0644]
pv/device/devinst.cpp
pv/device/devinst.h
pv/devicemanager.cpp
pv/sigsession.cpp
test/CMakeLists.txt

index aaed2d61d60603a90bd2673d9eece76142ee34cd..58c86c455f742b1a5918fd6a4187cccfb8bbf1bc 100644 (file)
@@ -127,6 +127,7 @@ set(pulseview_SOURCES
        pv/data/logicsnapshot.cpp
        pv/data/signaldata.cpp
        pv/data/snapshot.cpp
+       pv/device/device.cpp
        pv/device/devinst.cpp
        pv/dialogs/about.cpp
        pv/dialogs/connect.cpp
diff --git a/pv/device/device.cpp b/pv/device/device.cpp
new file mode 100644 (file)
index 0000000..ca18fc1
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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 <sstream>
+
+#include <libsigrok/libsigrok.h>
+
+#include "device.h"
+
+using std::ostringstream;
+using std::string;
+
+namespace pv {
+namespace device {
+
+Device::Device(sr_dev_inst *sdi) :
+       DevInst(sdi)
+{
+}
+
+std::string Device::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();
+}
+
+} // device
+} // pv
diff --git a/pv/device/device.h b/pv/device/device.h
new file mode 100644 (file)
index 0000000..fe91a6c
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * This file is part of the PulseView project.
+ *
+ * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk>
+ *
+ * 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_DEVICE_H
+#define PULSEVIEW_PV_DEVICE_DEVICE_H
+
+#include "devinst.h"
+
+namespace pv {
+namespace device {
+
+class Device : public DevInst
+{
+public:
+       Device(sr_dev_inst *dev_inst);
+
+       std::string format_device_title() const;
+};
+
+} // device
+} // pv
+
+#endif // PULSVIEW_PV_DEVICE_DEVICE_H
index a5f96808e55d14161050b5d3e966ca0e847b3c62..5fe2951756e4b602fca4da0fa4b379f3cfc19ef0 100644 (file)
@@ -19,7 +19,6 @@
  */
 
 #include <cassert>
-#include <sstream>
 
 #include <QDebug>
 
@@ -27,9 +26,6 @@
 
 #include "devinst.h"
 
-using std::ostringstream;
-using std::string;
-
 namespace pv {
 namespace device {
 
@@ -44,31 +40,6 @@ 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;
index 073813f2f7d1d03f418c05b07952ecc63fe784c4..6e81f49c686fcc8ab1424ed2836ae6e859e5e348 100644 (file)
@@ -42,12 +42,13 @@ class DevInst : public QObject
 {
        Q_OBJECT
 
-public:
+protected:
        DevInst(sr_dev_inst *sdi);
 
+public:
        sr_dev_inst* dev_inst() const;
 
-       std::string format_device_title() const;
+       virtual std::string format_device_title() const = 0;
 
        GVariant* get_config(const sr_probe_group *group, int key);
 
@@ -68,7 +69,7 @@ public:
 signals:
        void config_changed();
 
-private:
+protected:
        sr_dev_inst *const _sdi;
 };
 
index 11a5fe3c2ff9564f56ae1dfaf33c81e23eb16859..b854c05081123516948262249a632ca39372a80c 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #include "devicemanager.h"
-#include "device/devinst.h"
+#include "device/device.h"
 #include "sigsession.h"
 
 #include <cassert>
@@ -102,7 +102,7 @@ list< shared_ptr<device::DevInst> > DeviceManager::driver_scan(
        GSList *const devices = sr_driver_scan(driver, drvopts);
        for (GSList *l = devices; l; l = l->next)
                driver_devices.push_back(shared_ptr<device::DevInst>(
-                       new device::DevInst((sr_dev_inst*)l->data)));
+                       new device::Device((sr_dev_inst*)l->data)));
        g_slist_free(devices);
        driver_devices.sort(compare_devices);
 
index 622bf8d2c5b4dedf18143df7e5824282178c4995..4469a3eef367071c44a545d3c3a1a8ae746742cc 100644 (file)
@@ -25,7 +25,7 @@
 #include "sigsession.h"
 
 #include "devicemanager.h"
-#include "device/devinst.h"
+#include "device/device.h"
 
 #include "data/analog.h"
 #include "data/analogsnapshot.h"
@@ -127,7 +127,7 @@ void SigSession::load_file(const string &name,
                }
 
                shared_ptr<device::DevInst> dev_inst(
-                       new device::DevInst((sr_dev_inst*)devlist->data));
+                       new device::Device((sr_dev_inst*)devlist->data));
                g_slist_free(devlist);
 
                _decode_traces.clear();
@@ -147,7 +147,7 @@ void SigSession::load_file(const string &name,
 
                _decode_traces.clear();
                update_signals(shared_ptr<device::DevInst>(
-                       new device::DevInst(in->sdi)));
+                       new device::Device(in->sdi)));
                read_sample_rate(in->sdi);
 
                _sampling_thread = boost::thread(
index 27d42f916d69c1b44ca5ef2a1a2ca13bc52623db..5e064a027f04840031f3a30cccb8b7d836c14759 100644 (file)
@@ -57,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/device.cpp
        ${PROJECT_SOURCE_DIR}/pv/device/devinst.cpp
        ${PROJECT_SOURCE_DIR}/pv/prop/int.cpp
        ${PROJECT_SOURCE_DIR}/pv/prop/property.cpp